Computer Science
What will be the output when the following code is executed?
>>> strl = "helloworld"
>>> strl[ : : -1]
- dlrowolleh
- hello
- world
- 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
What is the output of the following ?
x = 123 for i in x: print(i)
- 1 2 3
- 123
- Error
- Infinite loop
Which arithmetic operator(s) cannot be used with strings ?
- +
- *
- -
- All of these
What is the output of the following statement?
python print("xyyzxyzxzxyy".count('yy', 1))
- 2
- 0
- 1
- Error
Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:
- [0, 1, 2, 3]
- [0, 1, 2, 3, 4]
- [0.0, 0.5, 1.0, 1.5]
- [0.0, 0.5, 1.0, 1.5, 2.0]