Skip to main content
Programming Languages

Python Tutorial with Examples.

Python tutorial with runnable examples: practical Python for automation, data engineering, machine learning, AI, DevOps, backend development and testing.

Beginner

Start here — no prior experience needed

16 lessons
python beginner
5 min read

Learn what Python is, its history, and real-world use cases — a practical Python tutorial for beginners starting from scratch.

python beginner
5 min read

Install Python, create and activate a virtual environment, install and freeze packages with pip, and run a first script, with real command output.

python beginner
5 min read

See how Python variables work by running them: names as references, mutable vs immutable objects, dynamic typing, PEP 8 names and LEGB scope.

python beginner
5 min read

Master Python's built-in data types — int, float, str, bool, None — and how to inspect and convert between them with real type conversion.

python beginner
5 min read

Run Python's arithmetic, comparison, identity, logical, membership, bitwise and walrus operators, plus operator overloading, and see each real result.

python beginner
5 min read

Slice, search, split, join and format Python strings with f-strings and format specs, plus escapes and raw strings, each example with real output.

python beginner
5 min read

Run if/elif/else, match-case, for and while loops, for/else, break/continue and comprehensions in Python, each example shown with its real output.

python beginner
5 min read

Define Python functions with positional, keyword, default, *args and **kwargs parameters, see the mutable-default trap, lambdas and return values run.

python beginner
5 min read

Use Python lists, tuples, dicts, sets and comprehensions through small runnable programs, plus a real timing of list vs set membership tests.

python beginner
5 min read

Work through list, dict, set and tuple, then deque, defaultdict, Counter and namedtuple from the collections module, each with its real printed output.

python beginner
5 min read

Build a real package step by step: import styles, the __name__ guard, __init__.py and __all__, relative imports, sys.path, venv and pyproject.toml.

python beginner
5 min read

Learn Python OOP — classes, objects, instances, inheritance, dunder methods, and encapsulation — with real-world examples.

python beginner
5 min read

Learn how Python encapsulates state with the underscore convention and name mangling, and why neither one is real access control.

python beginner
5 min read

See how Python's polymorphism works through duck typing, letting unrelated objects share behavior without a common base class or interface.

python beginner
5 min read

Use Python's abc module to define abstract base classes that force subclasses to implement required methods before they can be instantiated.

python beginner
5 min read

Build a weather command-line tool with argparse, split CLI and API code, package it with pyproject.toml, and test it offline with unittest.mock.

Intermediate

For developers with core concepts down

12 lessons
python intermediate
5 min read

See how Python resolves the diamond problem with C3 linearization (MRO), and use mixins to combine behavior from unrelated classes safely.

python intermediate
5 min read

Compare Python's has-a composition against is-a inheritance, and see how composition avoids the fragile base class problem.

python intermediate
5 min read

Use the @dataclass decorator to generate __init__, __repr__, and __eq__ automatically, plus frozen instances and post-init validation.

python intermediate
5 min read

Handle exceptions with try/except/else/finally, chain and re-raise them, define custom exceptions, use except* and logging, all with real tracebacks.

python intermediate
5 min read

Read and write text files with open() and with, choose the right file mode, navigate paths with pathlib, and round-trip JSON and CSV, all with real output.

python intermediate
5 min read

Build closures, then decorators: functools.wraps, decorator factories, stacking order, stateful class decorators and lru_cache, each with real output.

python intermediate
5 min read

Write generators with yield, see their lazy execution step by step, then build pipelines with yield from, send(), generator expressions and itertools.

python intermediate
5 min read

See exactly when __enter__ and __exit__ run, then build context managers with classes, @contextmanager, suppress and ExitStack, with real output.

python intermediate
5 min read

Run threads, processes and concurrent.futures side by side: see the GIL in real timings, a race condition and its Lock fix, queues and executors.

python intermediate
5 min read

Write and run pytest tests: assertions, exceptions, fixtures, parametrize, mocks, coverage, async tests and unittest, with real pytest output for each.

python intermediate
5 min read

Run real attacks against local Python code and fix them: SQL injection, shell injection, path traversal, weak tokens and password hashes.

python intermediate
5 min read

30 Python interview questions with concise answers and runnable code: the GIL, mutable defaults, decorators, MRO, closures, copying and more.

Advanced

Production-grade patterns for experienced engineers

6 lessons