Repaso
EspaƱol
PythonCorePY-47

What is "python"[-1]?

Options

  1. "p"
  2. "n" (Correct option)
  3. IndexError
  4. "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.

Key terms

Practice this question in Repaso