Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 6 of 102
Marks: +1, -0
What will be the output of the following code snippet ?
t = tuple('tuple')
t2 = t[2],
t += t2
print(t)
[CBSE 2026 Set 4]
Solution:  
Explanation:
t = tuple('tuple') → tuple() makes one element from each character: ('t', 'u', 'p', 'l', 'e')
t2 = t[2], → t[2] is 'p'; the trailing comma makes a one-element tuple: ('p',)
t += t2 → tuple concatenation creates a new tuple ('t', 'u', 'p', 'l', 'e', 'p') and binds it to t.
Output:
('t', 'u', 'p', 'l', 'e', 'p')
Key point: Tuples are immutable, but t += t2 is allowed because it builds a new tuple; the comma (not the brackets) makes t[2], a tuple.
Answer:
Option C (('t', 'u', 'p', 'l', 'e', 'p'))
© examsnet.com
Advertisements
Go to Question: