Questenaتدريب يوضح لك ما ينبغي مراجعته لاحقًا
السؤال 99

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

  1. It returns None.
  2. It returns 'c'.
  3. It raises KeyError.
  4. It raises IndexError.الإجابة الصحيحة

الشرح

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.

تابع هذا الاختبار

بدء التدريب
السؤال 99: What happens when Python evaluates "abc"[4]? · Python Fundamentals · Questena