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]

Answer: B. 'e'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",…

  1. A.

    'l'

  2. B.

    'e'

  3. C.

    'h'

  4. D.

    'B'

Attempted by 389 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

Loading lesson…