KnowledgeBoat Logo
|
LoginJOIN NOW

Computer Science

What is the correct Python code to display the last four characters of "Digital India"?

  1. str [-4 :]
  2. str [4 :]
  3. str [*4 :]
  4. str [/4 : ]

Python String Manipulation

1 Like

Answer

str [-4 :]

Reason — The Python code to display the last four characters of "Digital India" is str[-4:]. The negative index -4 starts the slice from the fourth-to-last character to the end of the string.

Answered By

3 Likes


Related Questions