Class 12 builds directly on the Python you learned in Class 11. Before we go further — into functions, files and stacks — let's blow the dust off the fundamentals. Skim what you remember, and run anything you're unsure about in the playground. If a section feels shaky, revisit the matching Class 11 chapter.
1Tokens, variables and data types
Recall the building blocks: keywords (reserved words), identifiers (names), literals (fixed values) and operators. Variables are created by assignment, and Python is dynamically typed — it infers the type from the value.
| Type | Example | Mutable? |
|---|---|---|
| int / float | 42, 3.14 | — |
| str | "hello" | No (immutable) |
| list | [1, 2, 3] | Yes |
| tuple | (1, 2, 3) | No (immutable) |
| dict | {"a": 1} | Yes |
Click Run to execute.
- Tokens: keywords, identifiers, literals, operators. Variables are created by assignment (dynamic typing).
- Numbers (int/float), strings, tuples are immutable; lists and dictionaries are mutable.
- type(x) reports the type of a value.
2Control flow and strings
Decisions use if / elif / else; repetition uses for (with range()) and while; break and continue alter the flow. Remember — Python uses indentation, not braces, to mark blocks.
Strings support indexing, slicing (s[start:stop:step]) and methods like upper(), lower(), split(), strip(), find() and replace() — and they're immutable, so every method returns a new string.
Click Run to execute.
- if/elif/else for decisions; for (with range) and while for loops; break/continue to control them.
- Indentation defines blocks in Python.
- Strings are immutable; slicing and methods return new strings.
3Lists, tuples and dictionaries
The three collections you'll use most:
- List — ordered, mutable:
append(),pop(),insert(),sort(). - Tuple — ordered, immutable; great for fixed data and packing/unpacking.
- Dictionary — key-value pairs, mutable:
keys(),values(),items(),get().
Click Run to execute.
- List = ordered + mutable; Tuple = ordered + immutable; Dictionary = key-value + mutable.
- Lists: append/pop/insert/sort. Dicts: keys/values/items/get. Tuples: packing/unpacking.
- Loop a dictionary with
for k, v in d.items().
★ Practical: warm-up program
In the playground, write one small program that:
- Stores three test marks in a list and prints their average.
- Uses an if/else to print 'pass' or 'fail' based on the average (pass mark 33).
- Stores a student's name and class in a dictionary and prints them with items().
- Reverses a string using slicing.
Ready for the chapter test?
Answer 5 questions. Score 60% or more to mark this chapter complete.
Start the test →💡 Log in to save your progress and earn the certificate.