The Complete Guide to Python¶
Python is the most popular programming language. Here is a complete guide.
Basics¶
Variables, types¶
name = “Python” version = 3.12 features = [“simple”, “powerful”, “readable”] config = {“debug”: True, “port”: 8080}
Functions¶
def greet(name: str, greeting: str = “Hello”) -> str: return f”{greeting}, {name}!”
Lambda¶
square = lambda x: x ** 2
OOP¶
from dataclasses import dataclass
@dataclass class User: name: str email: str active: bool = True
List Comprehensions¶
squares = [x**2 for x in range(10)] evens = [x for x in range(100) if x % 2 == 0] flat = [item for sublist in nested for item in sublist]
Generators¶
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Context Managers¶
with open(“file.txt”) as f: content = f.read()
Async¶
import asyncio
async def fetch(url): async with aiohttp.ClientSession() as session: async with session.get(url) as resp: return await resp.json()
Virtual Environment¶
python -m venv .venv source .venv/bin/activate pip install -r requirements.txt pip freeze > requirements.txt
Type Hints¶
from typing import Optional
def process(data: list[dict], limit: Optional[int] = None) -> list[str]: …
Tools¶
- uv/pip — package management
- ruff — linting + formatting
- mypy — type checking
- pytest — testing
- poetry/uv — dependency management
Tip¶
Python is easy to learn, hard to master. Focus on idiomatic Python — not just “working” code.