CBSE Class 12 Computer Science Question 39 of 120

Review of Python Basics — Question 13

Back to all questions
13
Question

Question 13

What will be the output when the following code is executed?

>>> strl = "helloworld"
>>> strl[ : : -1]
  1. dlrowolleh
  2. hello
  3. world
  4. helloworld
Answer

dlrowolleh

Reason — The code strl[::-1] reverses the string strl using slicing with a step of -1. This means it starts from the end of the string and moves towards the beginning, effectively reversing the order of characters in the string. Therefore, the output will be "dlrowolleh" which is the reverse of "helloworld".