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]
- A.
'l'
- B.
'e'
- C.
'h'
- 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'.