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

Python List calculation this is not about slicing

list=[3, 1, -1]
list [-1]=list [-2]
print(list)

ok my last post was closed, even though this is not about slicing. There are no semicolons. The question is an exam question from the Python Institute course. I do not understand why the result of this calculation is [3, 1, 1]

Can someone explain me how this works?

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

>Solution :

list[-1] means "the last item in the list".

list[-2] means "the next-to-last item in the list".

So, list [-1]=list [-2] means "assign the last item in the list to be the same as the next-to-last item in the list".

Honestly, I don’t understand your confusion…

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