CBSE Class 11 Computer Science Question 74 of 114

Tuples — Question 11

Back to all questions
11
Question

Question 1(k)

Find the output generated by following code fragments :

tuple = ( 'a' , 'b',  'c' , 'd' , 'e')
tuple = ( 'A', ) + tuple[1: ]  
print(tuple)
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.