Python Documentation
Concise, example-driven Python reference. Read the concept, see the code, then practice it in a Coddy journey.
Start a guided Python journeyGetting Started
- What Is Python?A plain-English introduction to Python — what it is, what it's used for, and why so many people pick it as their first programming language.
- Install PythonA step-by-step guide to installing Python on any operating system, checking the version, and knowing when you don't actually need to install anything.
- Run Python CodeThree ways to run Python code — the interactive shell, a saved .py file from the terminal, and from an editor — with guidance on when to use each.
- Python SyntaxThe minimal set of syntax rules Python cares about — indentation, line breaks, colons, and case sensitivity — explained without jargon.
- CommentsHow to write comments in Python — single-line with #, multi-line blocks, and docstrings for documenting functions and modules.
Variables & Data
- VariablesHow variables work in Python — assignment, naming rules, reassignment, and the mental model that keeps you out of trouble.
- Data TypesA tour of Python's built-in data types — numbers, strings, booleans, None, lists, tuples, sets, dicts — with examples and when to reach for each.
- StringsWorking with text in Python — creating strings, using f-strings, slicing, and the everyday methods like split, join, replace, and strip.
- f-StringsA practical guide to Python f-strings — embedding variables and expressions, formatting numbers and dates, and when to reach for the older format styles.
- Numbers & BooleansHow Python handles integers, floating-point numbers, and booleans — arithmetic, conversion, and the edge cases that trip people up.
- Input & PrintHow Python's print() and input() functions work — plus separators, end characters, and how to convert user input to numbers.
Control Flow
- OperatorsA complete tour of Python operators — arithmetic, comparison, logical, assignment, membership, and identity — with examples of each.
- if / elif / elseHow Python's if, elif, and else statements work — including truthy values, nested conditions, and the ternary if expression.
- for LoopsHow Python's for loop works — iterating over lists, strings, ranges, dictionaries, and anything else that's iterable, plus break, continue, and else.
- while LoopsWhen to pick a while loop over a for loop, how to avoid infinite loops, and the patterns that come up most often in real code.
- range()How range() works in Python — start, stop, step, negative ranges, and why it's lazy rather than materializing a list.
Collections
- ListsA working tour of Python lists — the most common collection — covering creation, indexing, slicing, append, sort, and the patterns you'll reach for most.
- TuplesWhen to reach for a tuple instead of a list — immutability, unpacking, named tuples, and the scenarios tuples are made for.
- SetsWhen to reach for a Python set — uniqueness, fast in checks, and the math-style operations (union, intersection, difference) that make sets powerful.
- DictionariesDictionaries are Python's key-value lookup structure — the one data type you'll reach for constantly once you're past the basics.
- List ComprehensionList comprehensions let you build a new list in a single readable line — mapping, filtering, or both — replacing the loop-and-append pattern.
Functions & Structure
- FunctionsHow to define and use functions in Python — parameters, return values, default arguments, keyword arguments, and naming habits that keep code readable.
- *args and **kwargsWhat *args and **kwargs mean, when to use them, and how to forward arguments cleanly between functions.
- LambdaWhat lambda is, what it's good for, and the handful of places where it actually earns its keep — plus when to reach for a named function instead.
- DecoratorsWhat Python decorators actually are, how to write your own, and the patterns (arguments, stacking, wraps) that make them worth using.
- Type HintsWhat Python type hints are, when they help, and the syntax for annotating variables, function signatures, containers, and optional values.
- Modules & ImportsHow Python's module system works — writing your own modules, importing from them, and using pip to install third-party packages.
- pip & PackagesHow to install, upgrade, and remove Python packages with pip — including PyPI, requirements files, and avoiding the global-install trap.
- Virtual EnvironmentsWhat a virtual environment is, why every real Python project needs one, and how to create and manage them with the built-in venv module.
- __main__ GuardWhat `if __name__ == '__main__'` actually does, why every serious Python script grows into that pattern, and how to structure a file as both a script and a module.
Advanced Iteration
Working with Real Data
- File HandlingHow to read and write files in Python — the with statement, text vs binary, and the safer modern path-based API.
- JSONHow to read and write JSON in Python — loads, dumps, reading from files, pretty printing, and handling the edge cases that come up with real data.
- CSV FilesHow to read and write CSV files in Python — the csv module, DictReader and DictWriter, handling headers, quoting, and when to reach for pandas instead.
- HTTP RequestsHow to make HTTP requests in Python with the requests library — GET, POST, query params, headers, JSON bodies, and handling errors.
- datetimeA practical tour of Python's datetime module — parsing, formatting, doing math on dates, and handling timezones without getting lost.
- RegexA hands-on introduction to Python's re module — searching, matching, capturing groups, replacement, and the patterns you'll reach for most.
Errors & Debugging
- ExceptionsHow to handle errors in Python — try/except/finally, catching specific exceptions, raising your own, and when to let an error propagate.
- Error Types & DebuggingA tour of the Python errors you'll meet most often — KeyError, ValueError, ModuleNotFoundError, EOFError — and the debugging habits that fix them quickly.