Skip to content

Python Programming from Zero

Your first language, learned properly.

Start with no programming experience and finish writing tested, well-structured Python programs that read files, call APIs and automate real tasks. Every module ends with something you can run.

01Getting started

Install Python and write your first programs.

  1. Installing Python, the REPL & an editorPython is a program that reads your code and runs it. You can type code into the interactive REPL to try ideas instantly, or save it in a .py file and run the whole script from the terminal or VS Code.13 min
  2. Values, variables & basic typesEvery value in Python has a type, such as int, float, str or bool. A variable is just a name that points to a value, and you can point it at a new value at any time.13 min
  3. Strings, f-strings, input & printStrings are sequences of characters you can index, slice and transform with methods. input() reads a line the user types, and print() with f-strings shows results neatly formatted.11 min

02Control flow & functions

Make decisions, repeat work and name it.

  1. Conditionals & boolean logicConditionals let a program choose what to do. Python checks if, then each elif, top to bottom, and runs only the first branch whose condition is true; else catches everything left.12 min
  2. for, while, range & break/continueLoops repeat work. A for loop walks through each item of a sequence or range; a while loop repeats as long as a condition stays true. break stops a loop early and continue skips to the next round.12 min
  3. Functions, parameters & return valuesA function is a named, reusable block of code. You define it once with def, call it with arguments, and it hands a value back with return. Small functions make programs easier to read, test and change.12 min
  4. Scope, None & pure functionsScope decides which variable a name refers to. Python looks up names Local first, then Enclosing, Global and finally Built-in. Pure functions only use their inputs and return outputs, so they are easy to predict and test.11 min
  5. Pattern matching with match/casematch/case (Python 3.10+) compares one value against a list of patterns and runs the first that fits. It can match literals, unpack tuples and check object types, often replacing long if/elif chains.11 min

03Core data structures

Lists, dicts and friends: most of everyday Python.

  1. Lists, tuples, slicing & sortingLists hold an ordered, changeable sequence of items; tuples hold an ordered, fixed record. Both support indexing, slicing and unpacking, and sorted() can order any sequence by a key you choose.12 min
  2. Dictionaries & setsA dict maps keys to values for instant lookup, which makes it ideal for counting and grouping. A set stores unique items and answers "is this in here?" quickly, plus union and intersection.11 min
  3. ComprehensionsA comprehension builds a list, dict or set in a single readable expression: loop over a source, optionally filter, and transform each item. It replaces the common create-empty-then-append pattern.12 min
  4. Mutability, references & copyingVariables hold references to objects, not copies. If two names point to the same mutable list, changing it through one name changes what the other sees. Copies give you an independent object when you need one.12 min
  5. Practice: small data problemsPractice turns syntax into skill. Each small problem follows the same loop: understand the input and output, plan with the right data structure, code it, then test normal and edge cases.11 min

04Files, errors & modules

Programs that survive real input and grow beyond one file.

  1. Reading & writing files with pathlibpathlib.Path represents file paths as objects that work on every OS. Opening files inside a with-block guarantees they are closed, even if an error happens while reading or writing.11 min
  2. Exceptions: try, except, raiseAn exception is Python's way of signalling that something went wrong. try/except lets you catch the specific errors you expect and recover, while raise lets your own code report problems clearly.11 min
  3. Modules, packages & importsA module is any .py file; a package is a folder of modules. Importing lets you split a program into focused files and reuse the huge standard library without copying code.11 min
  4. Virtual environments & pipA virtual environment is a private folder of installed packages for one project. pip installs packages into it, and a requirements.txt file records exact versions so anyone can recreate the same setup.11 min

05Object-oriented Python

Bundle data and behaviour when it helps.

  1. Classes, objects & methodsA class is a blueprint that bundles data (attributes) with behaviour (methods). Each object created from it is an instance with its own attribute values, set up by the __init__ method.11 min
  2. Inheritance, composition & dunder methodsInheritance lets a subclass reuse and override a parent class's behaviour. Composition builds objects out of other objects instead. Dunder methods like __repr__ and __eq__ make your objects print and compare nicely.10 min
  3. Dataclasses & enums@dataclass writes the boring parts of a class for you: __init__, __repr__ and __eq__ from the fields you list. Enums give a fixed set of named choices, replacing error-prone magic strings.11 min

06Idiomatic Python & the standard library

Write Python that looks like Python.

  1. collections, itertools, datetime & randomPython ships with a rich standard library. Counter and defaultdict simplify counting and grouping, itertools combines and slices iterables, datetime handles dates and times, and random makes samples and choices.11 min
  2. Iterators & generatorsAn iterator hands out values one at a time when asked with next(). Generators are the easy way to write iterators: a function with yield pauses after each value, so huge or endless data never has to sit in memory.11 min
  3. Decorators & context managersA decorator is a function that wraps another function to add behaviour, like timing or logging, without changing its code. A context manager wraps a block with setup and cleanup, which is what with-statements use.10 min
  4. Type hintsType hints label what types a function expects and returns. Python ignores them when running, but editors and type checkers like mypy or Pyright read them to catch mistakes before you run the code.12 min

07Testing, debugging & Git

The habits that make code trustworthy.

  1. Testing with pytestpytest finds functions named test_* and runs them, reporting which assertions fail. Fixtures share setup and parametrize runs one test over many inputs, so checking your code after every change takes seconds.10 min
  2. Debugging & reading tracebacksDebugging is finding out why code does something you did not expect. Read the traceback first, then pause the program at a breakpoint and inspect real values instead of guessing with scattered prints.12 min
  3. Linting & formatting with RuffA formatter rewrites code into one consistent style, and a linter flags likely bugs and bad habits. Ruff does both very fast, so style debates disappear and small mistakes get caught automatically.10 min
  4. Git basics for your projectsGit records snapshots of your project called commits, so you can see history, undo mistakes and try ideas on branches. Pushing to GitHub backs up your work and lets others see it.12 min

08Practical Python

Point your skills at real-world tasks.

  1. Working with CSV & JSON dataCSV is the common format for tables and JSON for nested data. Python's csv and json modules read them into lists and dicts, so you can clean, summarise and export data with the tools you already know.11 min
  2. Calling web APIs with requestsWeb APIs return data over HTTP, usually as JSON. The requests library sends a request with parameters and headers, then you check the status, parse the JSON and save or use the result.11 min
  3. Command-line tools with argparseargparse turns a script into a proper command-line tool. You declare the arguments and options it accepts, and argparse parses them, converts types, applies defaults and writes the --help text for you.10 min
  4. Automating everyday tasksAutomation means letting a script do a boring, repeatable task: renaming files, sorting downloads, or building a weekly report. Start with a dry run that only prints what would happen, then let it act.11 min

09Capstone project

One complete program you built yourself.

  1. Plan the project: features, data model & module layoutA short plan saves hours of rework. List the features you must have, sketch the data as dataclasses, and decide which module owns which job before writing any real code.11 min
  2. Build a CLI app (e.g. expense tracker or weather logger)The build brings every module of the path together: a venv and Ruff-checked repo, dataclass models, JSON storage, an argparse CLI, one web API call and pytest tests, documented in a README.11 min