Computer Science
Find the output generated by following code fragments :
t3 = (6, 7)
t4 = t3 * 3
t5 = t3 * (3)
print(t4)
print(t5)
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.
Related Questions
Find the output generated by following code fragments :
tuple = ( 'a' , 'b', 'c' , 'd' , 'e') tuple = ( 'A', ) + tuple[1: ] print(tuple)Find the output generated by following code fragments :
t2 = (4, 5, 6) t3 = (6, 7) t4 = t3 + t2 t5 = t2 + t3 print(t4) print(t5)Find the output generated by following code fragments :
t1 = (3,4) t2 = ('3' , '4') print(t1 + t2 )What will be stored in variables a, b, c, d, e, f, g, h, after following statements ?
perc = (88,85,80,88,83,86) a = perc[2:2] b = perc[2:] c = perc[:2] d = perc[:-2] e = perc[-2:] f = perc[2:-2] g = perc[-2:2] h = perc[:]