हिंदी

What will be the output of the following code snippet? t = tuple('tuple') t2 = t[2], t += t2 print(t) - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

What will be the output of the following code snippet?

t = tuple('tuple')

t2 = t[2],

t += t2

print(t)

विकल्प

  • (‘tuple’)

  • (‘tuple’,‘p’)

  • (‘t’, ‘u’, ‘p’, ‘1’, ‘e’, ‘p’)

  • (‘t’, ‘u’, ‘p’, ‘1’, ‘e’)

MCQ
Advertisements

उत्तर

(‘t’, ‘u’, ‘p’, ‘1’, ‘e’, ‘p’)

Explanation:
  1. The function tuple('tuple') breaks the string into individual characters, creating t = ('t', 'u', 'p', 'l', 'e').
  2. The statement t2 = t[2], creates a new tuple containing the character at index 2 (which is 'p') because of the trailing comma.
  3. Using t += t2 performs tuple concatenation, joining the two tuples together to produce the final output.
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2025-2026 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×