Computer Science, asked by Amans5730, 1 year ago

How to reverse a string in python using while loop?

Answers

Answered by Ragib11
2

Some of the common ways to reverse a string are:

1.Using Slicing to create a reverse copy of the string.

2.Using for loop and appending characters in reverse order

3.Using while loop to iterate string characters in reverse order and append them

4.Using string join() function with reversed() iterator

Creating a list from the string and then calling it's reverse () function

5.Using recursion

For example :-)

def reverse_slicing(s):

return s[::-1]

input_str = 'ABç∂EF'

if __name__ == "__main__":

print('Reverse String using slicing =', reverse_slicing(input_str))

Similar questions