Why is the output of these two statements different?

Question:

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

Asked By: essesoul

||

Answers:

list1 = my_list[1:9:2] It would be enough to write 10 instead of 9 here.

Answered By: MrSpyX
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.