QuestenaPractice that shows what to review next
Question 99

What happens when Python evaluates "abc"[4]?

  1. It returns None.
  2. It returns 'c'.
  3. It raises KeyError.
  4. It raises IndexError.Correct answer

Explanation

The string has valid nonnegative positions 0 through 2, so direct access at 4 raises IndexError. Direct indexing does not clip an excessive position or return None as a sentinel.

Continue with this test

Start practice
Question 99: What happens when Python evaluates "abc"[4]? · Python Fundamentals · Questena