Computer Science

Find the output generated by following code fragments :

t3 = (6, 7)  
t4 = t3 * 3  
t5 = t3 * (3)  
print(t4)  
print(t5)

Python Tuples

4 Likes

Answer

Output
(6, 7, 6, 7, 6, 7)  
(6, 7, 6, 7, 6, 7)  
Explanation

The repetition operator * replicates the tuple specified number of times. The statements t3 * 3 and t3 * (3) are equivalent as (3) is an integer not a tuple because of lack of comma inside parenthesis. Both the statements repeat t3 three times to form tuples t4 and t5.

Answered By

1 Like


Related Questions