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.
Python Basics
- Python Introduction — What Python is, what it's used for, and why it's a great first language.
- Python Get Started — Install Python, run a script and use the interactive shell.
- Python Syntax — Indentation, statements and how Python decides where a block starts and ends.
- Python Comments — Explain your code with single-line comments and docstrings.
- Python Variables — Create variables, name them well and reassign them to any type.
- Python Data Types — The built-in types: str, int, float, bool, list, tuple, dict, set and None.
- Python Numbers — Integers, floats, arithmetic and why 0.1 + 0.2 isn't exactly 0.3.
- Python Casting — Convert between types with int(), float(), str() and bool().
- Python Strings — Create strings, slice them, loop over characters and use common string methods.
- Python String Formatting — Build strings with f-strings, format specifiers and join().
- Python Booleans — True, False, comparisons and which values count as truthy or falsy.
- Python Operators — Arithmetic, comparison, logical, membership and identity operators.
- 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
- Python Lists — Ordered, changeable collections: create, access, slice and modify lists.
- Python List Methods and Comprehensions — Sort, search and transform lists — and write list comprehensions.
- Python Tuples — Immutable sequences, unpacking and returning several values from a function.
- Python Sets — Unordered collections of unique items and fast membership tests.
- Python Dictionaries — Key-value pairs: create, read safely, update, loop and nest dictionaries.
Control Flow
- Python If...Else — Make decisions with if, elif, else and conditional expressions.
- Python Match Statement — Structural pattern matching with match/case (Python 3.10+).
- Python While Loops — Repeat code while a condition is true, with break, continue and else.
- Python For Loops — Loop over lists, strings, ranges and dictionaries with enumerate() and zip().
Functions
- Python Functions — Define functions with def, return values and write docstrings.
- Python Function Arguments — Default values, keyword arguments, *args, **kwargs and keyword-only parameters.
- Python Lambda — Small anonymous functions for sorting keys and quick callbacks.
- Python Scope — Local, enclosing, global and built-in scope (LEGB), global and nonlocal.
Object-Oriented Python
- Python Classes and Objects — Define classes, create objects and use __init__, methods and __str__.
- Python Inheritance — Reuse and extend classes with inheritance, super() and method overriding.
- Python Dataclasses — Write data-holding classes with less boilerplate using @dataclass.
- Python Iterators and Generators — How for loops work, and generators that produce values lazily with yield.
Working with Data
- Python Modules and Imports — Import standard-library modules, your own files and third-party packages.
- Python Dates and Times — Create, format, parse and do arithmetic with dates using datetime.
- Python Math — Built-in math functions, the math module, random numbers and statistics.
- Python JSON — Convert between Python objects and JSON with json.dumps and json.loads.
- Python RegEx — Search, match, extract and replace text with regular expressions (re).
- Python Try...Except — Handle errors with try, except, else, finally and raise your own exceptions.
- Python File Handling — Read and write text files, CSV and paths safely with with-statements and pathlib.
Going Further
- Python pip and Virtual Environments — Install packages with pip inside an isolated virtual environment.
- Python Type Hints — Annotate functions and variables so editors and type checkers catch bugs early.
- Python Async and Await — Run I/O-bound work concurrently with asyncio, async def and await.
- Python Testing with pytest — Write tests with assert and pytest, and why tests matter.
- Python Next Steps — Where to go after the basics: projects, interview practice and frameworks.