Python Programming - Tricky Questions - Discussion

Discussion Forum : Tricky Questions - General Questions (Q.No. 2)
2.
What is the value of result after executing the following Python code?
my_list = [1, 2, 3, 4, 5]
result = my_list[::2]
[1, 3, 5]
[2, 4]
[5, 3, 1]
[1, 2, 3, 4, 5]
Answer: Option
Explanation:
The slicing notation my_list[::2] extracts elements with a step of 2, starting from index 0. Therefore, it includes elements at indices 0, 2, and 4, resulting in the list [1, 3, 5].
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.