Computer Science
Find the output generated by following code fragments :
tuple = ( 'a' , 'b', 'c' , 'd' , 'e')
tuple = ( 'A', ) + tuple[1: ]
print(tuple)
Python Tuples
5 Likes
Answer
Output
('A', 'b', 'c', 'd', 'e')
Explanation
tuple[1:]
creates a tuple slice of elements from index 1 (indexes always start from zero) to the last element i.e. ('b', 'c', 'd', 'e')
.+
operator concatenates tuple ( 'A', )
and tuple slice tuple[1: ]
to form a new tuple.
Answered By
3 Likes
Related Questions
Find the output generated by following code fragments :
T4 = (17) type(T4)
Find the output generated by following code fragments :
T5 = (17,) type(T5)
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 :
t3 = (6, 7) t4 = t3 * 3 t5 = t3 * (3) print(t4) print(t5)