- Lists:
items = [1, 2, 3]; items.append(4) - Dictionaries:
user = {"id": 1, "name": "Alice"}; print(user["name"]) - Tuples:
point = (10, 20) # Immutable - Sets:
unique = {1, 2, 2, 3} # Result: {1, 2, 3}
# List Comprehension
squares = [x**2 for x in range(5)] # [0, 1, 4, 9, 16]
# Context Manager
with open("test.txt", "w") as f:
f.write("Hello World")
# Decorator Example
def debug(func):
def wrapper(*args):
print(f"Calling {func.__name__}")
return func(*args)
return wrapper
@debug
def greet(name):
return f"Hi {name}"| Task | Command / Shortcut |
|---|---|
| Virtual Env | python -m venv .venv |
| Install Package | pip install <package_name> |
| Run Current File | Shift + F10 (PyCharm) |
| Debug Current File | Shift + F9 (PyCharm) |
| Toggle Breakpoint | Ctrl + F8 (PyCharm) |
| Step Over (Next Line) | F8 (While Debugging) |
| Step Into (Function) | F7 (While Debugging) |
| Resume Program | F9 (While Debugging) |
- Conditional Expressions:
result = "Pass" if score > 50 else "Fail" - Logical Truthiness:
0,"",[],{},Noneare all False. Everything else is True. - Debugging Tip: Use Conditional Breakpoints (Right-click a red dot) to pause a loop only when a specific value is met (e.g.,
i == 50).
FastAPI Snippet:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"status": "online"}Pandas Snippet:
import pandas as pd
df = pd.read_csv("data.csv")
print(df.describe()) # Statistical summaryFocus on syntax and basic problem solving.
- Variables, Data Types (Int, String, Float, Boolean).
- Basic Operators and Math.
- Conditional Logic (
if/elif/else). - Loops (
forandwhile). - Functions and Scope.
Mastering collections and efficiency.
- List/Dict/Set operations.
- List Comprehensions.
- File I/O (Reading/Writing files).
- Exception Handling (
try/except/finally). - Working with JSON and external data.
Thinking in systems and structures.
- Classes and Objects.
- Inheritance and Polymorphism.
- Encapsulation (Private variables).
- Dunder Methods (
__init__,__str__,__repr__). - Type Hinting.
Pick a path based on your goals.
- Web Development: FastAPI, SQL Alchemy, Pydantic.
- Data Science: NumPy, Pandas, Matplotlib, Scikit-learn.
- Automation: Requests, BeautifulSoup, Selenium.
- Testing: Pytest, Mocking.
Managing libraries correctly is the difference between "it works on my machine" and "it works everywhere."
| Action | Command | Description |
|---|---|---|
| Install | pip install <package> |
Installs the latest version of a library. |
| Snapshot | pip freeze > requirements.txt |
Saves all currently installed versions to a file. |
| Sync | pip install -r requirements.txt |
Installs everything listed in the requirements file. |
| Check | pip list |
Shows all installed packages and their versions. |
| Uninstall | pip uninstall <package> |
Removes a package from the environment. |