Code :
my_tuple = (5, 12, 19, 3, 25)
tup = my_tuple[-2::-2]
print(tup)
Let's break down the code:
Sure! The output of the code is:
(3, 12)
Explanation:
You created a tuple named my_tuple with five elements: 5, 12, 19, 3, and 25.
Then, you created another tuple named tup by slicing my_tuple from the second-last element (-2) to the first element (-1) with a step size of -2 (meaning you iterate from the second-last element to the first element, reversing the order every two elements).
Finally, you printed the tup tuple, which contains the elements extracted from my_tuple: (3, 12).
0 Comments:
Post a Comment