KnowledgeBoat Logo

Computer Science

Following set of commands is executed in shell, what will be the output?

>>>str = "hello"
>>>str[:2]
>>>
  1. he
  2. lo
  3. olleh
  4. hello

Python String Manipulation

5 Likes

Answer

he

Reason — str[:2] here slicing operation begins from index 0 and ends at index 1. Hence the output will be 'he'.

Answered By

1 Like


Related Questions