Learn Python: 20 free interactive lessons
Short lessons with real Python 3 running in your browser. Every example runs, every variable can be watched step by step, and you can change any line and run it again.
Do it in the browser: a real Python tool, a short mission and instant feedback. No install. Optional certificate at the end of the course.
Open the courseLessons
- Hello, printYour first program: tell Python to show something on the screen.
- VariablesGive a name to a value and use it again later.
- Numbers and textint, float and str: what each type can do and how to convert between them.
- Reading inputinput() pauses the program and returns what the user typed, always as text.
- True or FalseComparisons produce booleans, the raw material of every decision.
- if and elseRun a block only when a condition is true, otherwise run another.
- Many cases with elifCheck conditions in order and stop at the first true one.
- and, or, notA loan is approved only with enough income and no debts. One false part makes the whole and false.
- for and rangeRepeat a block once for each value in a sequence.
- while loopsRepeat while a condition stays true, for when you do not know how many times.
- AccumulatingSum, count and find the best value while you loop.
- break and continueLeave a loop early or skip to the next round.
- ListsAn ordered collection you can index, change and grow.
- SlicesTake a piece of a list or string with [start:stop:step].
- DictionariesStore values under keys: look up by name instead of position.
- ComprehensionsBuild a new list from another in one readable line.
- FunctionsPackage code under a name, give it inputs and get a result back.
- Handling errorstry/except lets a program react to problems instead of crashing.
- Classes and objectsBundle data and the functions that act on it into your own type.
- Project: word counterCombine strings, loops, dictionaries and functions in a real little tool.