Python Programming - Data Types - Discussion
Discussion Forum : Data Types - General Questions (Q.No. 39)
39.
What is the output of the following code snippet?
my_tuple = (1, 2, 3, 4, 5)
print(my_tuple[-2:])
Answer: Option
Explanation:
my_tuple[-2:]
slices the tuple my_tuple
starting from the second-to-last element (index -2) to the end of the tuple.
So, it selects elements at indices -2 and -1, which are 4 and 5 respectively, resulting in the tuple (4, 5)
.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers