📘 CodingMarble Learn

Python Revision for Class 12: Everything from Class 11 in One Place

Class 12 builds on Class 11 Python. You must know tokens (keywords, identifiers, literals, operators, punctuators), data types (int, float, bool, str, list, tuple, dict), which types are mutable (can change in place) and which are immutable, operator precedence, if-elif-else, for and while loops with break and continue, string slicing, and the main methods of lists, tuples and dictionaries.

🎬 Step-by-step story

  1. A variable is a name tag on a box. x = 5 puts the tag x on a box that holds 5.
  2. Some boxes can be changed in place (list, dict). Others cannot (int, str, tuple). Changing an immutable value makes a new box.
  3. Operators work in an order: ** first, then * / // %, then + -, then comparisons, then not, and, or.
  4. if-elif-else picks one path. for walks through items. while repeats while a condition is True. break stops the loop; continue skips one turn.
  5. Strings, lists and tuples are rows of numbered boxes. Index 0 is the first. s[1:4] takes boxes 1, 2, 3 (not 4). Negative index counts from the end.
  6. Your turn: pick a type and an action. See if Python changes the same box or makes a new one.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

If int is immutable, how can x = x + 1 work?

Python makes a new box with the new value and moves the name tag x to it. The old box is not changed.

Why is 2 ** 3 ** 2 equal to 512 and not 64?

** is done right to left: first 3 ** 2 = 9, then 2 ** 9 = 512.

Why does s[1:4] not include index 4?

The stop index is always left out. So s[1:4] gives 4 − 1 = 3 characters: index 1, 2, 3.

What is the difference between break and continue?

break leaves the whole loop. continue only skips the rest of this turn and goes on with the next item.

Does M = L copy a list?

No. It puts a second name tag on the same box. Change one and both show it. Use L.copy() for a new box.

Tokens: the smallest pieces of a program

A token is the smallest meaningful piece of a Python program. There are five kinds.

Data types and mutable vs immutable

Every value has a type. Use type(x) to see it.

Mutable and immutable

Mutable means "can be changed in the same place in memory". Immutable means "cannot be changed; a new value is made instead".

You can check with id(x). After L.append(4), id(L) stays the same. After n = n + 1, id(n) changes.

Operators and precedence

Order (highest first)

() → ** → unary - → * / // % → + - → comparisons → not → and → or. Note: ** works right to left, so 2**3**2 = 2**9 = 512.

Flow of control: if, for, while, break, continue

if-elif-else checks conditions from the top. The first True one runs; the rest are skipped.

for goes through each item: for i in range(1, 6): gives 1 to 5. range(start, stop, step) never includes stop.

while repeats as long as the condition is True. Change the variable inside, or the loop never ends.

break leaves the loop at once. continue skips the rest of this turn and goes to the next. A loop's else part runs only if the loop ended without break.

Strings

A string is a row of characters. Index 0 is the first; -1 is the last.

Slicing: s[start:stop:step]. For s = 'PYTHON': s[1:4] = 'YTH', s[::-1] = 'NOHTYP', s[-3:] = 'HON'.

Strings are immutable: s[0] = 'J' gives an error. Useful methods: len(), upper(), lower(), title(), count(), find(), replace(), split(), join(), strip(), isdigit(), isalpha().

Lists, tuples and dictionaries

List (mutable)

L = [10, 20, 30]. Methods: append(x) adds one item at the end, extend(seq) adds many, insert(i, x), pop(i) removes by index and returns it, remove(x) removes by value, sort(), reverse(), index(x), count(x).

Tuple (immutable)

T = (10, 20, 30). A one-item tuple needs a comma: (5,). Only count() and index(). Good for data that must not change.

Dictionary (mutable)

D = {'Asha': 92, 'Ravi': 75}. Keys must be unique and immutable. D['Zoya'] = 81 adds or updates. Methods: keys(), values(), items(), get(k), update(), pop(k), del D[k].

Try it: predict before you run

Open Python (IDLE or any online editor). For each line, write your guess first, then run it: print(7//2, -7//2, 7%3), print('PYTHON'[1:4]), L=[1,2]; M=L; M.append(3); print(L), print(2**3**2). Every wrong guess shows you a rule to revise. Then use the free-play step in the 3D to test mutable and immutable types.

Key formulas and definitions

Worked examples

1. Find the output: print(17 // 5, 17 % 5, 17 / 5)

17 // 5 = 3 (whole part). 17 % 5 = 2 (remainder). 17 / 5 = 3.4 (always float). Output: 3 2 3.4

2. Evaluate: 10 + 4 * 3 ** 2 // 6

** first: 3 ** 2 = 9. Then left to right among * and //: 4 * 9 = 36, 36 // 6 = 6. Then + : 10 + 6 = 16.

3. s = 'COMPUTER'. Find s[2:6], s[-3:], s[::2].

Indexes: C0 O1 M2 P3 U4 T5 E6 R7. s[2:6] = 'MPUT'. s[-3:] = 'TER'. s[::2] takes 0,2,4,6 = 'CMUE'.

4. L = [5, 2, 8]; M = L; M.append(1); print(L). What is printed and why?

M = L does not copy; both names point to the same list. Appending through M changes that one list. Output: [5, 2, 8, 1].

5. Write a program to count vowels in a string entered by the user.

s = input('Enter text: ') count = 0 for ch in s.lower(): if ch in 'aeiou': count += 1 print('Vowels:', count)

6. D = {'a': 1, 'b': 2}. After D['a'] = 10 and D['c'] = 3, what is D? What does D.get('z', 0) return?

An existing key is updated; a new key is added. D = {'a': 10, 'b': 2, 'c': 3}. D.get('z', 0) returns 0 because 'z' is not a key (no error).

Common mistakes

Practice quiz

1. Which type is mutable?
2. What is 2 ** 3 ** 2?
3. What does 'PYTHON'[-2:] give?
4. Which is a valid identifier?
5. Which statement skips the rest of the current loop turn?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is covered in Python revision tour for Class 12?

Tokens, data types, mutable and immutable types, operators and precedence, if and loops, strings, lists, tuples and dictionaries from Class 11.

What is the difference between a list and a tuple?

A list uses [ ] and can be changed. A tuple uses ( ) and cannot be changed after it is made.

What are mutable and immutable types in Python?

Mutable objects (list, dict, set) can be changed in place. Immutable objects (int, float, str, tuple, bool) cannot; a change creates a new object.

Where this is taught

CBSE (India)Class 12Python Programming II
CBSE (India)Class 12Computational Thinking and Programming - 2
FranceSecondeAlgorithms and logic
FranceSecondeProgramming basics
FrancePremièreAlgorithms and logic
FrancePremièreLanguages and programming
FrancePremièreMathematics (2026 programme)
FranceTerminaleContent
FranceTerminaleMathematics (2019 programme)

Learn first

Learn next

Related lessons

All Computer Science lessons