+ 2

What happens if you attempt to access an element of a list using a negative index?

29th Dec 2018, 8:27 AM
Pradeep Kumar
Pradeep Kumar - avatar
3 odpowiedzi
+ 7
HonFu yes you're right. Pradeep Kumar List indexes of -x means the xth item from the end of the list, so for example n[-1] means the last item in the list n. Next time don't forget to include the Programming language in the tag.
29th Dec 2018, 8:42 AM
Ikechukwu Okonkwo
Ikechukwu Okonkwo - avatar
+ 5
You read from the back of the list if it's Python - or you go where you shouldn't go if it's C.
29th Dec 2018, 8:36 AM
HonFu
HonFu - avatar
+ 5
HonFu Also with ruby you will go backward 😄
29th Dec 2018, 9:33 AM
Sekiro
Sekiro - avatar