cd ../labs
Pythonbeginnerabout 35 minutes
Python basics
Indentation, lists and dictionaries, loops and the traps that catch newcomers, by reading code and predicting what it does.
By the end you can
- Read Python's block structure with confidence
- Work with lists, dictionaries and slices
- Predict what a loop or comprehension produces
- Avoid the mutable default argument trap
0 of 2 done
step 1 of 2
Blocks, lists and dictionaries
Python marks blocks with indentation instead of braces. The indentation is the syntax, not a style choice, and mixing tabs with spaces is a real error.
Lists are ordered and changeable. Dictionaries map keys to values. Both are everywhere.
Read each snippet and say what it prints. Reading before writing is the fastest way into a new language.
question 1 of 4
What does this print?
prices = [360, 600, 1000] print(prices[1]) print(prices[-1])question 2 of 4
What does prices[1:3] give?
prices = [360, 600, 1000, 1800] print(prices[1:3])question 3 of 4
What happens here?
plan = {"name": "Starter", "price": 600} print(plan["months"])question 4 of 4
What does this print?
total = 0 for price in [360, 600, 1000]: if price >= 600: total += price print(total)