CBSE Class 11 Computer Science Question 25 of 34

Tuples — Question 30

Back to all questions
30
Question

Question 6

Find the error. Following code intends to create a tuple with three identical strings. But even after successfully executing following code (No error reported by Python), The len( ) returns a value different from 3. Why ?

tup1 = ('Mega') * 3 
print(len(tup1))
Answer
Output
12 
Explanation

This is because tup1 is not a tuple but a string. To make tup1 a tuple it should be initialized as following:
tup1 = ('Mega',) * 3
i.e., a comma should be added after the element.
We are getting 12 as output because the string "Mega" has four characters which when replicated by three times becomes of length 12.

Get the Bright Tutorials app Stuck on a question? Ask Bright Buddy — your AI tutor — for step-by-step help in the app.