Python

Python tutorials, written for beginners.

Short, complete guides to the parts of Python you'll use every day. Each one has runnable examples with their real output, the mistakes people make, and exercises with answers.

Start here, in this order

Every tutorial stands on its own, but this order builds each idea on the last. Every example runs as shown in Python 3.

Part 1 of 8

Variables, keywords and identifiers in Python

What an identifier is in Python, the naming rules, the reserved keywords you can't use, and how variables really work as names bound to objects.

Part 2 of 8

Python data types

Python data types explained: int, float, str, bool, None, list, tuple, set and dict. How to check a type with type() and convert between types.

Part 3 of 8

Python lists

A practical guide to Python lists: creating them, indexing and slicing, adding and removing items, sorting, copying, list comprehensions and common mistakes.

Part 4 of 8

Python dictionaries

How Python dictionaries work: creating them, reading and updating values, get(), looping with items(), nesting, dictionary comprehensions and common errors.

Part 5 of 8

The Python for loop, and how range() works

How the Python for loop works: looping over lists, strings and range(), using start, stop and step, enumerate, zip, and the mistakes beginners make.

Part 6 of 8

The Python while loop

How the Python while loop works: conditions, counters, input validation, avoiding infinite loops, while True with break, and when to use for instead.

Part 7 of 8

break, continue and else on Python loops

How break, continue and pass work in Python for and while loops, what the else clause on a loop does, how break behaves in nested loops, and when to use each.

Part 8 of 8

Python modules, packages and import

How import works in Python: import, from … import, aliases, the standard library, your own modules, packages, __name__ and installing with pip.

Want video lessons and a person to ask?

Stage 1 of Foundations of AI, SchoolWhool's course, is Python from zero, and it's free: video lessons, notebooks that check your answers, and a human who replies to your doubts within 12 hours.

Python first. Then machine learning, from first principles.