Fundamentals Highlights Summary
Every highlight bullet from the 12 pages in this section, gathered on one page and grouped by the page it came from.
- A 'variable' is a name bound to an object in a namespace, not a labeled memory slot
- Namespaces are dictionaries; LEGB is just a search order across a chain of them
- def, class, and import all do the same thing: create an object and bind a name to it
- A module's top-level code runs exactly once per process, then sys.modules caches the result
- Names bind to objects - assignment never copies by default
- f-strings are the default formatting tool
- match/case handles structural patterns beyond simple equality
- Comprehensions beat manual append loops for clarity
- Names are labels; objects carry type information
- Assignment shares references - not copies
- id() and is expose object identity
- Type hints annotate names for static tools only
- int has arbitrary precision in Python 3
- Use Decimal for money, not float
- / always returns float; // floors toward negative infinity
- bool is a subclass of int
- str is Unicode; bytes is raw binary
- f-strings are the default formatting choice
- encode/decode with explicit encodings
- split/join/strip cover most text parsing
- match/case destructures shape, not just values
- for/while else runs only without break
- Short-circuit and/or avoid unnecessary work
- enumerate and zip improve loop readability
- Comprehensions are faster and clearer than manual append loops
- Generator expressions are lazy and memory-efficient
- Dict/set comps build collections in one expression
- Nested comprehensions need readable line breaks
- LEGB resolves names: Local, Enclosing, Global, Built-in
- Keyword-only params follow a bare *
- Never use mutable default arguments
- nonlocal mutates enclosing function state
- Prefer absolute imports in application code
- Run packages with python -m
- Circular imports need lazy imports or restructuring
- src layout keeps imports unambiguous
- pathlib is the default path API
- Always specify encoding=utf-8 for text
- with blocks guarantee file closure
- Binary mode uses bytes, not str
- Never install project deps into system Python
- uv is the fastest path to venv + lock + sync
- Activate venv so python and pip point locally
- Commit pyproject.toml, not the venv folder
- Explicit is better than implicit - Zen of Python
- Use venv and pinned deps from day one
- Prefer pathlib and f-strings in new code
- Let ruff and mypy catch mistakes early
Y29kZWd1aWRlcy5pb3xjZ2lvNzIwfDIwMjYwNw==
Revisado por Chris St. John·Última atualização: 31 de jul. de 2026