Computer Science

Which of the following functions will return the first three characters of a string named 's'?

  1. s[3:]
  2. s[:3]
  3. s[-3:]
  4. s[:-3]

Python String Manipulation

1 Like

Answer

s[:3]

Reason — The slice s[:3] returns the first three characters of the string s. The slice starts from the beginning (index 0) up to index 2.

Answered By

3 Likes


Related Questions