KnowledgeBoat Logo

Computer Science

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

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

Python String Manipulation

1 Like

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".

Answered By

1 Like


Related Questions