Lessons · Python
Learn Python step by step: 9 lessons with runnable examples
Each lesson pairs a plain-English explanation with code you can run. Try the examples in the playground, compare the output and change an input to see how the behavior changes.
Lesson 1
Python Printing and Output
Learn what print really does in Python - quotes and strings, printing values with commas, the sep and end settings, escapes and multi-line text.
print · output · basics · 1 exercise to practice it
Lesson 2
Python Variables and Data Types
Understand what a Python variable really is, how to name one well, and how int, float, str, bool, and None behave when you check and convert types.
variables · data-types · basics · 1 exercise to practice it
Lesson 3
Python Arithmetic and Numbers
How Python does maths - why division always gives a float, what // and % really answer, powers, int versus float, and why 0.1 + 0.2 is not 0.3.
arithmetic · numbers · operators · floats · 1 exercise to practice it
Lesson 4
Python Conditionals: if, elif, and else
Learn how Python decides what to run using if, elif, and else, plus comparison operators, and/or/not, truthiness, and the conditional expression.
conditionals · control-flow · booleans · 1 exercise to practice it
Lesson 5
Python For Loops and Iteration
Learn Python for loops from the ground up - iterate over lists and strings, use range, enumerate and zip, and steer a loop with break and continue.
loops · iteration · control-flow · 3 exercises to practice it
Lesson 6
Python Strings
Learn how Python strings are created, why they are immutable, how indexing and slicing work, and the string methods and f-string formatting you will use most.
strings · text · f-strings · 2 exercises to practice it
Lesson 7
Python Lists
Learn how Python lists store ordered, changeable collections of values, and how to create, access, modify, and iterate over them.
lists · data-structures · 1 exercise to practice it
Lesson 8
Python Functions: Defining, Calling, and Returning
Learn Python functions from scratch - def syntax, parameters versus arguments, return values, keyword and default arguments, *args, **kwargs, and scope.
functions · parameters · scope
Lesson 9
Python Dictionaries
Learn how Python dictionaries map keys to values, read them safely with .get(), add, update and delete entries, loop with .items(), and why lookups are fast.
dictionaries · data-structures · hash-tables
Reading is half of it
The Python exercises are where you write the code these lessons describe, one idea at a time, with the output checked for you. The playground is for trying any example on this page with your own numbers.