Ask Your Question
3

What is the reason that this slice with negative index produces a list with no elements?

asked 2023-06-14 05:39:43 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-14 05:56:01 +0000

scrum gravatar image

The reason is because negative indexing starts counting from the end of the list. In this case, the negative index -1 refers to the last element of the list, and since the slice goes up to but not including the same index (-1), there are no elements left to include in the resulting list.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-14 05:39:43 +0000

Seen: 17 times

Last updated: Jun 14 '23