Python for beginners
Start from zero: variables, text, numbers, decisions, loops, lists, dictionaries, functions, errors and files, with a small project at the end.
This course takes you from your first line of code to a small working program. Every lesson has code you can run and change right in the page, exercises that check your answer, and a short quiz. You do not need to install anything.
- 1Your first Python programMeet Python, write your first line of code with print(), run it right in the page and leave notes with comments.10 min
- 2Variables: give your data a nameStore values in variables, change them, learn the basic types (str, int, float, bool) and the rules for good names.12 min
- 3Numbers and maths in PythonWhole numbers and decimals, the maths operators including //, % and , the order of operations and rounding with round().14 min
- 4Strings: working with textCreate strings with quotes, join them, build text with f-strings, pick letters with indexes and slices, and use common string methods.16 min
- 5Getting input from the userAsk the user a question with input(), understand why the answer is always text, and turn it into a number with int() or float().12 min
- 6Making decisions with if, elif and elseCompare values, run code only when a condition is true with if, choose between options with elif and else, and combine conditions with and, or, not.15 min
- 7Lists: keep many values togetherCreate lists, read items by index, add, change and remove items, sort them and use sum(), min(), max() and len() on them.15 min
- 8for loops: repeat for every itemUse a for loop to run code for every item in a list or string, count with range(), keep running totals and number items with enumerate().15 min
- 9while loops, break and continueRepeat code as long as a condition is true with while, stop a loop with break, skip a round with continue, and build a number-guessing game.15 min
- 10Dictionaries: look things up by nameStore key-value pairs in a dictionary, read values safely with get(), add, change and remove entries, loop over items and count things.16 min
- 11Tuples and setsUse tuples for fixed groups of values and unpack them into variables; use sets to remove duplicates and compare groups.14 min
- 12Functions: write your own commandsDefine functions with def, pass in parameters, send results back with return, give parameters default values and understand local variables.18 min
- 13Errors and exceptionsRead Python's error messages, know the common error types, catch problems with try and except, and raise errors with your own messages.16 min
- 14Reading and writing filesOpen text files with open(), read them whole or line by line, write and append text, and let the with statement close files for you.16 min
- 15Project: an expense trackerPut the whole course together: read expenses from a text file, total them per category with a dictionary and print a neat report.25 min