Python Tokens, Identifiers, Variables, Data Types and Mutability Class 11
Updated 17 October 2026 · Fact-checked
Python source is made of tokens: keywords, identifiers, literals, operators and punctuators. An identifier starts with a letter or underscore, contains letters, digits and underscores, is case-sensitive and cannot be a keyword. A variable refers to an object; numbers, strings, tuples are immutable, while lists, dictionaries and sets are mutable, which decides what happens when two names refer to the same object.
After b = b + 5 the int gets a new object, but y.append(3) changes the one list that both x and y share.
Illustration drawn for QuestionBuddy.
Understand Python Tokens, Identifiers, Variables, Data Types and Mutability
Tokens. The smallest units: keywords (if, for, True), identifiers (names), literals (5, 2.5, "hi", True, None), operators (+, ==) and punctuators (:, (, ,).
Identifier rules. Start with a letter or underscore; the rest can be letters, digits or underscores; no spaces or special characters like - or $; case-sensitive (total and Total are different); cannot be a keyword. Valid: my_var, _x, Class, total2. Invalid: 2nd (starts with a digit), total-marks (hyphen), class (keyword), my var (space).
Variables and assignment. a = 10 makes the name a refer to an integer object. a, b = 3, 4 assigns two values; a, b = b, a swaps them (a becomes 4, b becomes 3). x = y = 7 gives both names the value 7. In x = x + 1 the left side is the l-value (a name that receives) and the right side is the r-value (an expression that gives a value).
Data types. int (5), float (5.0), str ("5"), bool (True, False), NoneType (None), list, tuple, dict, set. type() gives the type: type(5) is int, type(5.0) is float, type("5") is str, type(True) is bool.
Mutable and immutable. Immutable objects cannot be changed after creation: int, float, bool, str, tuple. Mutable objects can be changed in place: list, dict, set.
a = 10
b = a
b = b + 5
print(a, b)Output: 10 15. Integers are immutable; b + 5 makes a new object and b now refers to it.
x = [1, 2]
y = x
y.append(3)
print(x)Output: [1, 2, 3]. Both names refer to the same list, which was changed in place.
Comments. A line starting with # is ignored by Python. Dynamic typing. The same name can later refer to an object of a different type.
Python Tokens, Identifiers, Variables, Data Types and Mutability: key facts
- Identifier rules
- Start with a letter or underscore
- Then letters, digits, underscore
- No spaces or symbols
- Case-sensitive
- Not a keyword
- Valid: _x, Total2. Invalid: 2nd, my-var, if.
- Immutable types
- int
- float
- bool
- str
- tuple
- A new object is made when changed.
- Mutable types
- list
- dict
- set
- Changed in place; aliases see the change.
- Useful functions
type object id object print value - type gives the class of the object.
How to answer Python Tokens, Identifiers, Variables, Data Types and Mutability questions
Tracing questions depend on whether the object is mutable and whether a name was rebound or the object changed.
- 1Draw each name pointing to its object.
- 2For immutable objects, an update makes a new object and rebinds the name.
- 3For mutable objects, methods like append change the shared object.
- 4For identifier questions, test each rule in order: first character, other characters, keyword.
- 5Write the output with the exact type names, such as <class 'int'>.
Python Tokens, Identifiers, Variables, Data Types and Mutability in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Two names for one list
Suppose a teacher writes marks = [40, 50] and then team = marks. A student later does team.append(60).
What does marks now contain, and why?
Try it first, then show the solutionSolution
- marks and team refer to the same list object.
- append changes that object in place.
Answer: marks is [40, 50, 60].
Memory hook: Same list, two labels.
Tricks to remember Python Tokens, Identifiers, Variables, Data Types and Mutability
Short memory aids. Say each one aloud once, then use it on a question the same day.
Strings and tuples are locked
Immutable: int, float, bool, str, tuple.
Use it when: Mutability.
Start with a letter, no hyphen
Identifiers cannot begin with a digit or contain hyphens.
Use it when: Valid names.
Python Tokens, Identifiers, Variables, Data Types and Mutability: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Valid identifier · 1 mark · MCQBoard level
Which of the following is a valid Python identifier?
(a) 2nd_value
(b) total-marks
(c) _total2
(d) class
Try it first, then show the solutionSolution
- It cannot start with a digit, cannot have a hyphen, and cannot be a keyword.
Answer: (c) _total2
Example 2: Invalid names · 4 marks · Short answerBoard level
State why each is invalid as an identifier: (i) 2nd; (ii) my var; (iii) for; (iv) total-marks. (4 marks)
Try it first, then show the solutionSolution
- (i) Starts with a digit.
- (ii) Contains a space.
- (iii) It is a keyword.
- (iv) Contains a hyphen, which is an operator character.
Answer: (i) digit first (ii) space (iii) keyword (iv) hyphen
Example 3: Integers versus lists · 4 marks · Short answerHarder board level
Give the output and explain:
a = 10
b = a
b = b + 5
print(a, b)
x = [1, 2]
y = x
y.append(3)
print(x)(4 marks)
Try it first, then show the solutionSolution
- First part: b = a makes both refer to 10. b + 5 creates 15 and b refers to it; a stays 10. Output: 10 15.
- Second part: x and y refer to one list. append changes that list. Output: [1, 2, 3].
- The first case uses an immutable int, the second a mutable list.
Answer: Outputs: 10 15 and [1, 2, 3].
Example 4: type() and multiple assignment · 4 marks · Short answerHarder board level
Give the output:
print(type(5), type(5.0), type("5"), type(True), type(None))
a, b = 3, 4
a, b = b, a
print(a, b)(4 marks)
Try it first, then show the solutionSolution
- The first print gives the classes in order: <class 'int'> <class 'float'> <class 'str'> <class 'bool'> <class 'NoneType'>.
- a, b = 3, 4 assigns a = 3, b = 4. The next line swaps them: a = 4, b = 3.
- Second print: 4 3.
Answer: <class 'int'> <class 'float'> <class 'str'> <class 'bool'> <class 'NoneType'> and then 4 3.
Example 5: Copy or alias · 5 marks · Short answerHOTS / competency
Trace the output and say which statement makes a true copy:
a = [1, 2, 3]
b = a
c = a[:]
b.append(4)
c.append(5)
print(a, b, c)(5 marks)
Try it first, then show the solutionSolution
- b = a is an alias; c = a[:] makes a new list with the same items.
- b.append(4) changes the shared list: a and b are both [1, 2, 3, 4].
- c.append(5) changes only c: [1, 2, 3, 5].
- Output: [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 5]. The slice a[:] makes the copy.
Answer: Output: [1, 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 5]; the slice makes the copy.
Where students lose marks in Python Tokens, Identifiers, Variables, Data Types and Mutability
The slips examiners see most often, and what to write instead.
Mistake: Saying lists are immutable
Confusing lists and tuples.
Wrong working
A list is an immutable type.
Right working
A list is mutable; a tuple is immutable.
Do this: List: changeable; tuple: fixed.
Usually costs: 1 mark
Mistake: Believing b = a copies a list
Assignment copies the reference.
Wrong working
b is a new list after b = a.
Right working
b and a refer to the same list.
Do this: Use a[:] or copy() for a copy.
Usually costs: 1 mark
Mistake: Starting an identifier with a digit
Overlooking the first-character rule.
Wrong working
1total is valid.
Right working
1total is invalid.
Do this: First character: a letter or underscore.
Usually costs: 1 mark
Exam tips
- Write the object each name refers to when tracing.
- Write exact output including brackets and spaces.
- Give a reason for every invalid identifier.
- Mention "mutable" or "immutable" in the explanation of each trace.
Practice questions on Python Tokens, Identifiers, Variables, Data Types and Mutability
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
Which of the following is mutable?
(a) int
(b) str
(c) tuple
(d) listHint
Changeable in place.
Answer
(d) list
Q2 · 3 marks · Short answerHarder board level
What is the output?
x = 5 y = x x = x * 2 print(x, y) s = "ab" t = s s = s + "c" print(s, t)(3 marks)
Hint
Immutable objects are rebound.
Answer
x = 5; y = 5; x becomes 10, y stays 5. Output: 10 5. s = "abc" is a new string; t stays "ab". Output: abc ab.
Q3 · 3 marks · Short answerHarder board level
Write the data type of: 7, 7.0, "7", 7 > 3, [7], (7,), {7: 7}, None. (3 marks)
Hint
Think of the literal.
Answer
int, float, str, bool, list, tuple, dict, NoneType.
Q4 · 1 mark · Assertion-reasonHarder board level
Assertion (A): After a = [1, 2]; b = a; b[0] = 9, the value of a[0] is 9.
Reason (R): a and b refer to the same list object.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
Alias.
Answer
(a) Both A and R are true, and R is the correct explanation of A.
Q5 · 5 marks · Short answerHOTS / competency
Find the output and explain each line:
a = [1, 2] b = a a = a + [3] print(a, b)How does it differ from a.append(3)? (5 marks)
Hint
a + [3] makes a new list.
Answer
a + [3] creates a new list [1, 2, 3] and rebinds a; b still refers to the old list [1, 2]. Output: [1, 2, 3] [1, 2]. With a.append(3) the same list is changed, so b would also show [1, 2, 3].
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Can an identifier start with a digit?Show answer
No.
2.Is a list mutable?Show answer
Yes.
3.Is a string mutable?Show answer
No.
4.Function that gives the type?Show answer
type().
5.What does a, b = b, a do?Show answer
Swaps the values.
Python Tokens, Identifiers, Variables, Data Types and Mutability: frequently asked questions
What is a token?
The smallest unit of a Python program: keyword, identifier, literal, operator or punctuator.
Is Python case-sensitive?
Yes; total and Total are different names.
What is dynamic typing?
A name can refer to objects of different types at different times.