Python for beginners
From your first print() to classes, generators and decorators: 31 short lessons, one idea each. Every example runs right on the page, and you can change it and step through it. Each lesson ends with exercises that check your code.
Every example runs in your browser. No install, no account, and you can step through any of them.
Part 1 · Basics8
- 1Hello, World!Write and run your first Python program in your browser. Learn print(), quotes, sep and end, \n, comments, and how to read your first error message.
- 2Variables and typesLearn Python variables: how to create and change them, naming rules, the basic types int, float, str, bool and None, type(), converting types and f-strings.
- 3Numbers and mathDo math in Python: + - * /, floor division //, remainder %, powers **, order of operations, int vs float, rounding, +=, min, max, abs and the math module.
- 4StringsWork with text in Python: join and repeat strings, len(), indexing from the front and back, slicing, reversing with [::-1], why strings can't change, and multi-line strings.
- 5String methodsLearn the Python string methods you will use every day: upper, lower, title, strip, find, count, replace, split and join, the in operator, chaining, and methods in f-strings.
- 6User inputAsk the user a question with input(), turn the answer into a number with int() and float(), clean it up, and build a small calculator.
- 7Booleans and comparisonsLearn True and False, the comparison operators == != < > <= >=, chained comparisons, comparing strings, and, or, not, and which values count as true.
- 8if, elif and elseMake your Python programs decide with if, else and elif. Learn indentation, combined conditions, nested if, one-line conditional expressions and common mistakes.
Part 2 · Collections and loops7
- 9ListsLearn Python lists in your browser: create them, read items by index and slice, add and remove items, search, sort, sum numbers and copy a list safely.
- 10TuplesLearn Python tuples in your browser: create them, read items, why they cannot change, unpack them into variables, and when to pick a tuple over a list.
- 11DictionariesLearn Python dictionaries in your browser: look up values by key, use get() safely, add, change and remove entries, keys, values and items, and count things.
- 12SetsLearn Python sets in your browser: remove duplicates, add and remove items, fast membership tests with in, and union, intersection and difference.
- 13for loopsRepeat code with Python for loops. Loop over lists, strings and dictionaries, count with range(), and use enumerate(), zip(), break and continue.
- 14while loopsRepeat code until something happens with Python while loops. Learn while True with break, continue, infinite loops, checking input and a guessing game.
- 15ComprehensionsBuild lists, dictionaries and sets in one line with Python comprehensions. Turn a loop into a comprehension, filter with if, use if-else, and know when not to.
Part 3 · Functions5
- 16FunctionsComing soon
- 17Function argumentsComing soon
- 18ScopeComing soon
- 19lambda, map and filterComing soon
- 20RecursionComing soon
Part 4 · Code and data5
- 21Errors and exceptionsComing soon
- 22Modules and importsComing soon
- 23Reading and writing filesComing soon
- 24String formattingComing soon
- 25Dates and timesComing soon
Part 5 · Objects3
- 26Classes and objectsComing soon
- 27InheritanceComing soon
- 28Special methodsComing soon
Part 6 · Going further3
- 29Iterators and generatorsComing soon
- 30DecoratorsComing soon
- 31Type hintsComing soon
Questions
Is it really free?
Yes. Every lesson, example and exercise is free, and there is no account to make.
Do I need to install Python?
No. The code runs in your browser on a Python interpreter we wrote ourselves, so it starts at once, and you can watch it run one line at a time.
Is it real Python?
It is Python 3. Every example in the course is checked against the real Python, output and error messages included. Our interpreter covers what beginners use; for big projects and libraries such as pandas or Django, install Python from python.org.
Do I need any programming experience?
No. Lesson 1 starts with print(), and each lesson only uses what came before. If you already know another language, skim the basics and use the exercises to find what is new.
Is Python a good first language?
Yes. Python reads almost like English, so you can think about ideas such as variables, loops and functions rather than punctuation. It is also one of the most used languages for automation, data, the web and teaching.
How long does it take?
Each lesson takes 15 to 20 minutes. At a lesson or two a day you can finish the course in about a month. Getting comfortable with your own projects takes a few months of regular practice.
Can I learn on my phone?
Yes. Reading, running, stepping and the exercises all work on a phone; a keyboard helps with the longer exercises.
Where is my progress kept?
In this browser, with no account. A different device, or clearing the browser's data, starts you over.
What should I do after the course?
Write your own small programs in the Playground, or play the games: Town Lab, Code Island and Pathfinding all use Python.