CBSE Class 12 Computer Science Question 25 of 105

Python Revision Tour II — Question 4

Back to all questions
4
Question

Question 4

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
Answer

he

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