Skip to main content

Python Basics

Learn Python as a small set of interacting models, not a catalog of methods.

This section is a Python 3.10+ reference for small synchronous programs: names and objects, functions and control flow, strings and collections, classes, and local files. It does not cover packaging, asynchronous execution, concurrency, or the full standard library. Start with syntax, then functions, conditionals, and loops; read lists and classes before the tree example in recursion. Code with undefined names such as process is an API pattern, not a standalone script. Complete examples include their inputs and assertions; assertions are learning checks, not input validation, since Python can disable them with -O.

Learning path​

QuestionPage
How do names, objects, expressions, and imports work?Basic Syntax
How should behavior be packaged and called?Functions
How does a program choose a branch?Conditionals
How does it consume an iterable or repeat until a condition?Loops
When is self-similar decomposition useful?Recursion
How is Unicode text represented and transformed?Strings
Which mutable sequence should hold ordered values?Lists
How are keys mapped to values?Dictionaries
How do objects own state and behavior?Object-Oriented Programming
How should files and paths cross the program boundary?Reading and writing / Paths

Core mental model​

  • Variables are names bound to objects; assignment does not copy an object.
  • Every object has a type, identity, and value.
  • Mutability determines whether an object can change; the operation's contract determines whether it actually mutates or returns a result.
  • Iteration asks an iterable for values; it is not limited to numeric indexes.
  • Exceptions communicate failures across call boundaries.
  • Modules and packages create namespaces and reusable ownership boundaries.

Working rules​

  1. Prefer clear data flow and small functions over clever expression density.
  2. Make mutation and I/O visible at boundaries.
  3. Use standard-library types and protocols before inventing wrappers.
  4. Add annotations to communicate contracts, then use tooling if enforcement is required; Python does not enforce most annotations by itself.
  5. Test behavior rather than copying interpreter output into notes.

Sources​

Explore connectionsOpen network