What is output of the code in Python Language: >>> str1 = 'All the Best' >>>…

2021

What is output of the code in Python Language: >>> str1 = 'All the Best' >>> str1[-3]

  1. A.

    'l'

  2. B.

    'e'

  3. C.

    'h'

  4. D.

    'B'

Attempted by 122 students.

Show answer & explanation

Correct answer: B

In Python, negative indexing starts from the end of the string:

-1 → last character (t)

-2 → second last (s)

-3 → third last (e)

Given "All the Best", str1[-3] = 'e'.

Explore the full course: Rssb Senior Computer Instructor