CBSE Academic Curriculum Code: 083|Senior School Certificate Examination (Class XII)|Theory: 70 Marks • Practicals: 30 Marks
Browser Cache Database Active (Zero Login Required)
learn.gradient.clothing
Class 12 CBSE Computer Science Learning Portal & Python IDE

1.1Lexical Tokens

A Token is the smallest lexical unit the Python compiler recognises. Five categories:

Token ClassDefinitionExamples
KeywordsReserved; cannot be used as identifiersif, else, for, while, def, return, global, pass, break, continue, import, from, in, not, and, or, True, False, None…
IdentifiersUser-defined names for variables, functions, classesMust start with letter or _; case-sensitive; no special chars
LiteralsFixed data values embedded in source42, 3.14, 'hello', True, None
OperatorsSymbols that perform operations+, -, *, /, //, %, **, ==, !=, <, >, and, or, not, in, is
PunctuatorsStructural delimiters( ) [ ] { } , : . ;
Exam Trap — Identifiers
  • Identifiers are case-sensitive: Datadata.
  • Cannot begin with a digit; no $, @, or other special chars.
  • 1varSyntaxError; _var1 → valid.

1.2Data Types, Mutability & Memory Reference2–3 marks

In Python, variables are reference pointers to heap-allocated objects. id(x) returns the unique memory address of object x.

Data TypeMutabilityIn-place Modificationid() after reassignment
int, float, complexImmutable✗ ProhibitedChanges — new object created
strImmutable✗ TypeError on item assignmentChanges — new string buffer
tupleImmutable✗ ProhibitedChanges — new tuple object
listMutable✓ append, pop, slice assign…Same — buffer mutated in place
dictMutable✓ key-value insert/update/popSame — hash-map mutated
setMutable✓ add, discard, removeSame — hash-bucket mutated
Exam Trap — id() Questions
  • For immutable types: x = x + 1id(x) changes (new object).
  • For mutable types: lst.append(4)id(lst) stays same (in-place).
  • is checks identity (same id()); == checks equality (same value).
# Immutable rebinding
x = 100
print(id(x))
x += 1          # New PyObject allocated; id(x) differs
print(id(x))

# Mutable in-place
nums = [1, 2, 3]
print(id(nums))
nums.append(4)  # Same buffer; id(nums) identical
print(id(nums))

1.3Operators & Operator Precedence1–2 marks

Operator GroupSymbolsNote
Arithmetic+ − * / // % **// → floor division; ** → exponentiation
Relational== != < > <= >=Returns bool
Logicaland or notShort-circuit evaluation
Membershipin not inWorks on str, list, tuple, dict (checks keys), set
Identityis is notCompares memory address, not value
Assignment= += -= *= /= //= %= **=Augmented assignment operators
Precedence Order (High → Low)
** → +x −x (unary) → * / // % → + − → Relational → not → and → or

1.4Conditional & Iterative Statements2–3 marks

  • if / elif / else — standard conditional branching.
  • for — iterates over any iterable (list, str, range, tuple…).
  • while — repeats while condition is True.
  • break — terminates the innermost loop immediately.
  • continue — skips remaining body; proceeds to next iteration.
  • pass — null statement; placeholder for empty block.
  • range(start, stop, step) — generates integers from start up to but not including stop.
Exam Trap — Loop-else Clause (frequently tested)

A for or while may have an else suite.

  • The else block executes only when the loop completes normally (exhausts all iterations OR condition becomes False) without hitting a break.
  • If break is executed → else is skipped entirely.
for i in range(1, 4):
    if i == 5: break
else:
    print("Executes — no break hit")   # OUTPUT: Executes — no break hit

for i in range(1, 4):
    if i == 2: break
else:
    print("Skipped — break was hit")   # NOT printed

1.5String Operations & Slicing2–3 marks

Strings are immutable sequences. Positive index: 0 → n−1 (left-to-right). Negative index: −1 → −n (right-to-left).

Syntax: s[start : stop : step] — stop is excluded; step default = 1.

ExpressionResult (s = 'PYTHON')Explanation
s[0]'P'First character
s[-1]'N'Last character
s[1:4]'YTH'Index 1, 2, 3 (4 excluded)
s[::-1]'NOHTYP'Reversed copy
s[::2]'PTO'Every alternate character
Prescribed String Functions (exam-tested)
FunctionDescription
s.upper() / s.lower()Convert case
s.title()Title-case (first letter of each word capitalised)
s.strip() / s.lstrip() / s.rstrip()Remove whitespace (or specified chars)
s.replace(old, new)Replace all occurrences of old with new
s.find(sub)Return first index of sub; −1 if not found
s.count(sub)Count non-overlapping occurrences
s.split(sep)Split into list by separator
s.isdigit() / s.isalpha() / s.isalnum()Character-class predicates → bool
len(s)Number of characters

1.6Lists2–3 marks

Lists are ordered, mutable sequences enclosed in [ ]. Support heterogeneous elements.

Method / OperationEffect
lst.append(x)Appends x at end
lst.insert(i, x)Inserts x at index i
lst.pop() / lst.pop(i)Removes & returns last element (or element at i)
lst.remove(x)Removes first occurrence of x; ValueError if absent
lst.sort()Sorts in-place (ascending by default)
lst.reverse()Reverses in-place
lst.index(x)Returns index of first occurrence of x
lst.count(x)Returns count of x in list
len(lst)Number of elements
lst + lst2Concatenation — returns new list
lst * nRepetition — returns new list
Exam Trap — List Operations
  • remove(x) deletes by value; pop(i) deletes by index.
  • sort() is in-place (returns None); sorted(lst) returns a new sorted list.
  • Slicing a list always returns a new list — original is unmodified.

1.7Tuples

  • Ordered, immutable sequences enclosed in ( ). Heterogeneous allowed.
  • Indexing and slicing syntax identical to lists.
  • Only two methods: t.count(x), t.index(x).
  • Single-element tuple: (42,) — the trailing comma is mandatory.
  • Tuples are faster than lists and used as dictionary keys (lists cannot be).

1.8Dictionaries2–3 marks

Unordered (insertion-ordered from Python 3.7+) mutable key–value mappings. Keys must be immutable (str, int, tuple); values may be any type.

Method / OperationEffect
d[key]Access value; KeyError if absent
d.get(key, default)Access value; returns default (None) if absent — no KeyError
d.keys()View of all keys
d.values()View of all values
d.items()View of all (key, value) pairs
d.update(d2)Merges d2 into d
d.pop(key)Removes key and returns its value
del d[key]Removes entry by key
len(d)Number of key-value pairs
key in dMembership test on keys
Central Board of Secondary Education (CBSE) — Computer Science (Code 083)
Unit I: Computational Thinking and Programming (Python) • Unit II: Database Management (SQL)
Client-Side Database ActiveZero Tracking / No Remote Accountslearn.gradient.clothing
CBSE Class XII Computer Science (083) | Compendium & Python IDE