Free tutorial · 42 lessons

Python Tutorial

Learn Python from scratch: syntax, variables, strings, lists, dictionaries, loops, functions, classes, files, JSON, regular expressions, error handling, type hints, async and testing — with examples you can run in your browser.

Start learning →

Python Basics

  1. Python Introduction — What Python is, what it's used for, and why it's a great first language.
  2. Python Get Started — Install Python, run a script and use the interactive shell.
  3. Python Syntax — Indentation, statements and how Python decides where a block starts and ends.
  4. Python Comments — Explain your code with single-line comments and docstrings.
  5. Python Variables — Create variables, name them well and reassign them to any type.
  6. Python Data Types — The built-in types: str, int, float, bool, list, tuple, dict, set and None.
  7. Python Numbers — Integers, floats, arithmetic and why 0.1 + 0.2 isn't exactly 0.3.
  8. Python Casting — Convert between types with int(), float(), str() and bool().
  9. Python Strings — Create strings, slice them, loop over characters and use common string methods.
  10. Python String Formatting — Build strings with f-strings, format specifiers and join().
  11. Python Booleans — True, False, comparisons and which values count as truthy or falsy.
  12. Python Operators — Arithmetic, comparison, logical, membership and identity operators.
  13. Python History & Versions — Where Python came from, how it grew from a hobby project into one of the most used languages, every major release on one timeline, what changed between Python 2 and 3, and which version to use today.

Data Structures

  1. Python Lists — Ordered, changeable collections: create, access, slice and modify lists.
  2. Python List Methods and Comprehensions — Sort, search and transform lists — and write list comprehensions.
  3. Python Tuples — Immutable sequences, unpacking and returning several values from a function.
  4. Python Sets — Unordered collections of unique items and fast membership tests.
  5. Python Dictionaries — Key-value pairs: create, read safely, update, loop and nest dictionaries.

Control Flow

  1. Python If...Else — Make decisions with if, elif, else and conditional expressions.
  2. Python Match Statement — Structural pattern matching with match/case (Python 3.10+).
  3. Python While Loops — Repeat code while a condition is true, with break, continue and else.
  4. Python For Loops — Loop over lists, strings, ranges and dictionaries with enumerate() and zip().

Functions

  1. Python Functions — Define functions with def, return values and write docstrings.
  2. Python Function Arguments — Default values, keyword arguments, *args, **kwargs and keyword-only parameters.
  3. Python Lambda — Small anonymous functions for sorting keys and quick callbacks.
  4. Python Scope — Local, enclosing, global and built-in scope (LEGB), global and nonlocal.

Object-Oriented Python

  1. Python Classes and Objects — Define classes, create objects and use __init__, methods and __str__.
  2. Python Inheritance — Reuse and extend classes with inheritance, super() and method overriding.
  3. Python Dataclasses — Write data-holding classes with less boilerplate using @dataclass.
  4. Python Iterators and Generators — How for loops work, and generators that produce values lazily with yield.

Working with Data

  1. Python Modules and Imports — Import standard-library modules, your own files and third-party packages.
  2. Python Dates and Times — Create, format, parse and do arithmetic with dates using datetime.
  3. Python Math — Built-in math functions, the math module, random numbers and statistics.
  4. Python JSON — Convert between Python objects and JSON with json.dumps and json.loads.
  5. Python RegEx — Search, match, extract and replace text with regular expressions (re).
  6. Python Try...Except — Handle errors with try, except, else, finally and raise your own exceptions.
  7. Python File Handling — Read and write text files, CSV and paths safely with with-statements and pathlib.

Going Further

  1. Python pip and Virtual Environments — Install packages with pip inside an isolated virtual environment.
  2. Python Type Hints — Annotate functions and variables so editors and type checkers catch bugs early.
  3. Python Async and Await — Run I/O-bound work concurrently with asyncio, async def and await.
  4. Python Testing with pytest — Write tests with assert and pytest, and why tests matter.
  5. Python Next Steps — Where to go after the basics: projects, interview practice and frameworks.