0
What is the input of programme to print reverse of a string without using slice operator???
String s
5 Antworten
+ 4
You can also use a simple while loop or a nice comprehension: [Edited: added a for loop]
# using while loop
text = 'Hello World'
i = len(text)-1
while i >= 0 :
print(text[i], end='')
i -= 1
# using comprehension
[print(i, end='') for i in reversed(text)]
# using for loop
for i in reversed(range(len(text))):
print(text[i], end='')
+ 3
Hint - Use charAt(i) in Java in Reverse order.
+ 2
print(''.join(reversed('Hello')))
+ 1
For loop(index from end to start)
Revesed function
+ 1
string = "string S" # Your string
print(*reversed(string),sep='')