Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🐍 Unit 1 – Python Revision & Functions  ·  Lesson 01

Python Revision Tour

Tokens, variables and data types

Class XII builds on everything from Class XI. A Python program is made of tokens: keywords (if, def, return), identifiers (total), literals (25, 'CS', True, None), operators (+ == and) and punctuators (( ) [ ] : ,). Variables are names bound to objects; the type comes from the value (dynamic typing).

Data 📁 types/
├── 📁 Numbers/      int, float, complex, bool
├── 📁 Sequences/    str, list, tuple
├── 📁 Mapping/      dict
├── 📁 Set/          set
└── None
Built-in data types

Mutable vs immutable

Immutable

  • int, float, bool, str, tuple
  • Changing creates a new object
  • Can be dictionary keys

Mutable

  • list, dict, set
  • Changed in place — every name sharing it sees the change
  • Cannot be dictionary keys
The most tested concept in output questions
Python
a = [1, 2, 3]
b = a
c = a[:]
b.append(4)
c.append(5)
print(a, b, c)
s = 'cs'
s2 = s
s2 += '12'
print(s, s2)
[1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 5] cs cs12

b = a creates an alias; c = a[:] creates a copy. Strings are immutable, so s2 += '12' makes a new string and s is unchanged.

Operators and precedence

Order from high to low: () → ** (right to left) → unary + - ~ → * / // % → + - → comparisons, in, is → not → and → or.

Python
print(5 // 2 * 2, 2 ** 3 ** 0, not 0 or 5, 7 and 0, 'a' < 'B')
4 2 True 0 False

7 and 0 returns 0 (the first false value); 'a' < 'B' is False because 'a' is 97 and 'B' is 66.

Flow of control

⬇️
SequenceStatements run one after another.
🔀
Selectionif, if-else, if-elif-else, nested if.
🔁
Iterationfor (with range or a sequence), while; break, continue, loop-else.
Three control structures
Python
x = 10
while x > 0:
    x -= 3
print(x)
for i in range(3):
    pass
else:
    print('loop finished, i =', i)
-2 loop finished, i = 2

Strings

B0o1a2r3d4␣5E6x7a8m9
s[6:10] → "Exam"
Python
s = 'Board Exam 2026'
print(s[6:10], s[-4:], s.lower().count('a'))
print(s.split(), s.replace(' ', '-'))
Exam 2026 2 ['Board', 'Exam', '2026'] Board-Exam-2026

Must-know methods: len, upper, lower, title, capitalize, count, find, index, replace, split, join, strip, startswith, endswith, isalpha, isdigit, isalnum, isupper, islower, isspace.

Lists, tuples and dictionaries

Python
L = [5, 'two', 3.0, [7, 8]]
print(len(L), L[3][1], L[-2:])
t = (1, 2, 3) * 2
print(t, t.index(3))
d = {'a': 1}
d.setdefault('b', 2)
print(d, list(d.items()))
4 8 [3.0, [7, 8]] (1, 2, 3, 1, 2, 3) 2 {'a': 1, 'b': 2} [('a', 1), ('b', 2)]
TypeKey methods
listappend, extend, insert, pop, remove, index, count, sort, reverse, copy, clear
tuplecount, index (and len, max, min, sum, sorted)
dictkeys, values, items, get, update, pop, popitem, setdefault, copy, clear, fromkeys

Comprehensions

Python
print([i * i for i in range(6) if i % 2])
print({k: len(k) for k in ['cs', 'ip', 'maths']})
[1, 9, 25] {'cs': 2, 'ip': 2, 'maths': 5}

Board-style output questions

Find the output (trace word by word):

Python
text = 'Python Is Easy To Learn'
words = text.split()
new = ''
for w in words:
    if len(w) > 2:
        new += w[0].lower() + w[1:].upper() + ' '
    else:
        new += w + ' '
print(new.strip())
pYTHON Is eASY To lEARN
✅ Try yourself

Predict: L = [2, 4, 6]; L[1:2] = [9, 9]; print(L, len(L)) and print('-'.join('CS'.lower() * 2)).

Answers: [2, 9, 9, 6] 4 and c-s-c-s.

Quick revision table

ConceptRemember
Integer division-7 // 2 = -4 (floor), -7 % 2 = 1
Slicings[a:b] excludes b; s[::-1] reverses
Single-item tuple(5,) not (5)
Dictionary keysUnique, immutable
Alias vs copyb = a shares; a[:], list(a), a.copy() copy
Loop elseRuns only if no break

Frequently Asked Questions

Which Class 11 topics are needed for Class 12 CS?
Data types, operators, flow of control, strings, lists, tuples and dictionaries. Board papers regularly ask output and error-finding questions on these.
What is the value of 2 ** 3 ** 0?
2, because ** is evaluated right to left: 3 ** 0 = 1, then 2 ** 1 = 2.
What does not 0 or 5 return?
True. not 0 is True, and or returns the first true operand, which is True.
← Class 12 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicFunctions: Types & Arguments Your progress: 1 / 26 (4%) · Lesson 2 / 26 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free