33 lessons · Python 3.14 runs in your browser · No account
Learn Python
Python is a general-purpose programming language that reads close to plain English, which makes it a common first language. Each lesson here is short, runs real code on the page, and ends with an exercise the page checks, then a quiz.
name = "World"
print(f"Hello, {name}!")Hello, World!
Every lesson looks like this. Edit the code, press Run, read the real output.
What you'll learn
1Getting started8 lessons
- 1. Hello World (finished)Write and run your first Python program. Print Hello, World! with nothing to install, see the real output, fix a broken version and take a short quiz.
- 2. Variables (finished)Learn what a Python variable is, how to create one, the rules for names, and how a variable changes value and type, with examples you can run.
- 3. Data types (finished)The built-in Python data types, how to check a value's type with type(), how to convert between types, and which ones can change, with runnable examples.
- 4. Numbers (finished)How Python numbers work, with int and float, the seven arithmetic operators including floor division and modulo, why 0.1 + 0.2 is not 0.3, and rounding.
- 5. Strings (finished)How Python strings work, with quotes, indexing, slicing, the most useful methods, why strings never change, escapes and raw strings.
- 6. String formatting (finished)Format Python strings with f-strings. Put variables in text, show 2 decimal places, add thousands separators, align columns, and recognize %s and format().
- 7. Input and output (finished)Read what the user types with input() in Python, turn it into a number, and control print() with end and sep, including how to print without a newline.
- 8. Comments (finished)Write Python comments with #, comment out several lines with one shortcut, learn why triple quotes are not comments, and add a docstring to a function.
2Making decisions4 lessons
- 9. Booleans and comparisons (finished)How Python booleans work, with True and False, the six operators that compare values, why True == 1, what bool() treats as False, and == versus is.
- 10. if, elif and else (finished)How if, elif and else work in Python, why elif exists, the one-line form, nested ifs, and the exact error messages a missing colon or indent produces.
- 11. Logical operators (finished)The logical operators and, or and not in Python, with a truth table, why && is an error, short-circuit rules, the values they return, and precedence.
- 12. match statement (finished)Python has no switch keyword, but since 3.10, match and case do the job. Learn case _, matching several values with |, guards, and why no break is needed.
3Loops3 lessons
- 13. for loops (finished)How a Python for loop works, with range() for counting, loops over strings and lists, enumerate() for the index, and the errors beginners meet first.
- 14. while loops (finished)How a Python while loop works, when it runs zero times, what an infinite loop is, the while True and do-while patterns, and for versus while.
- 15. break and continue (finished)What break and continue do in Python, how they differ from pass, how nested loops run and how to leave one, and what an else clause after a loop means.
4Collections6 lessons
- 16. Lists (finished)How Python lists work, with examples for creating a list, indexing from 0 and -1, slicing, changing items, len() and lists of lists, plus common errors.
- 17. List methods (finished)Every Python list method with its output, including append() versus extend(), remove() versus pop(), sort() versus sorted(), and the errors they raise.
- 18. List comprehension (finished)How a Python list comprehension works, shown next to the for loop it replaces, with if filters, if/else expressions, two for clauses and common mistakes.
- 19. Tuples (finished)What a Python tuple is, how to create one, why it cannot be changed, tuple unpacking, converting to a list, and when to pick a tuple over a list.
- 20. Dictionaries (finished)How Python dictionaries work, with examples for creating one, get() with a default, adding and removing keys, looping with items(), and the KeyError trap.
- 21. Sets (finished)How Python sets store unique values, with set(), add() and remove(), union and intersection, removing duplicates from a list, and set versus list.
5Functions and modules6 lessons
- 22. Functions (finished)How to define and call a Python function with def, pass arguments to parameters, return a result, and why a function that only prints returns None.
- 23. Function arguments (finished)Positional and keyword arguments in Python, default parameter values, the shared mutable default trap, *args, **kwargs and unpacking a list into a call.
- 24. Lambda functions (finished)What a Python lambda is, how to write one, and how to use it as a key for sorted(), max() and min() or with map() and filter(), plus lambda versus def.
- 25. Variable scope (finished)How variable scope works in Python, local versus global variables, the global and nonlocal keywords, why UnboundLocalError happens, and the LEGB rule.
- 26. Modules and imports (finished)How to import a Python module, the difference between import and from import, aliases with as, writing your own module, __name__ and installing with pip.
- 27. Errors and exceptions (finished)Read a Python traceback, catch errors with try and except, use else and finally, raise exceptions on purpose, and learn the common built-in exceptions.
6Objects and data5 lessons
- 28. Classes and objects (finished)Define a Python class, create objects from it, set attributes in __init__, write methods that use self, and give objects readable output with __str__.
- 29. Inheritance (finished)Make a Python subclass, override methods, call parent methods with super(), check an object's class with isinstance(), and create custom exceptions.
- 30. Files (finished)Python file handling with open() and the with statement. Read and write text files, read line by line, append, pick a file mode and set the encoding.
- 31. JSON (finished)Parse JSON strings with json.loads(), turn Python data into JSON with json.dumps(), read and write JSON files, pretty-print, and fix JSONDecodeError.
- 32. Dates and times (finished)Get today's date with Python's datetime module, format dates with strftime, parse strings, add days with timedelta, and handle UTC and time zones.
Frequently asked questions
Is Python easy to learn?
Python is one of the easier languages to start with. Its code reads close to English, and you can try it without installing anything. Getting good at it still takes practice, which is why every lesson here has an exercise.
How long does it take to learn Python?
It depends on how often you practice. The lessons here are short enough that you can finish each one in a single sitting, and the basics stick fastest when you also write small programs of your own.
Can I learn Python on my own for free?
Yes. The course is free and needs no account, and every lesson runs real Python on the page. The official tutorial at docs.python.org is a good companion to it.
Do I need to install anything to follow along?
No. A copy of Python runs on each lesson page, so every runnable example and exercise works without installing anything. A few extras, such as importing your own module or converting named time zones, need Python on your own computer, and the Installing Python lesson shows how to set it up on Windows, macOS and Linux.
Is my progress saved?
Yes, on this device, with no account. Answer every quiz question in a lesson and that lesson gets a check mark wherever the course lists it. Progress is tied to the browser that saved it, so it does not carry over to another browser or device, and clearing site data resets it.
Which version of Python does this course use?
The examples run on Python 3.14 and give the same output on 3.15, the newest release, apart from a few differences the lessons point out. To run programs on your own computer, install 3.15. Error messages there show your own file paths, and input() waits for you to type instead of reading a lesson's input box.























