0

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

essesoul
  • 21
  • 6

1 Answers1

0

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

MrSpyX
  • 51
  • 2
  • At first I was worried that changing the 9 of `my_list[1:9:2]` to 10 would overflow. Now I think I get it. Thanks. – essesoul Oct 23 '22 at 14:43