Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is the output of these two statements different?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading