Q. 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 = Because here ‘tup1’ is not tuple, it is string. If we modify the program then len() return 3.

 

Program is: -

 

tup1 = ('Mega',) * 3

print(len(tup1))

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post