What is "python"[-1]?
Options
- "p"
- "n" (Correct option)
- IndexError
- "o"
Answer
"n"
Why
Positions (indexes) start at 0 from the left: "p" is 0, "y" is 1, and so on.
Negative indexes count from the right: -1 is the last character, -2 the one before it.
So "python"[-1] is "n". This works the same for lists.
Remember
Index 0 = first item, index -1 = last item.