Advertisements
Advertisements
Question
What will be the output of the following code snippet?
t = tuple('tuple')
t2 = t[2],
t += t2
print(t)
Options
(‘tuple’)(‘tuple’,‘p’)(‘t’, ‘u’, ‘p’, ‘1’, ‘e’, ‘p’)(‘t’, ‘u’, ‘p’, ‘1’, ‘e’)
MCQ
Advertisements
Solution
(‘t’, ‘u’, ‘p’, ‘1’, ‘e’, ‘p’)
Explanation:
- The function
tuple('tuple')breaks the string into individual characters, creatingt = ('t', 'u', 'p', 'l', 'e'). - The statement
t2 = t[2],creates a new tuple containing the character at index 2 (which is'p') because of the trailing comma. - Using
t += t2performs tuple concatenation, joining the two tuples together to produce the final output.
shaalaa.com
Is there an error in this question or solution?
