Issue
In a python program, define a list: my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
The output results of executing the following two statements are different:
1:
list1 = my_list[1:9:2]
print(list1)
output:[2, 4, 6, 8]
2:
list2 = my_list[1::2]
print(list2)
output:[2, 4, 6, 8, 10]
I can't understand why there is no "10" in the output of the first statement
Solution
list1 = my_list[1:9:2] It would be enough to write 10 instead of 9 here.
Answered By - MrSpyX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.