How do you reverse any string in python?



How do you reverse any string in python?..

Answer / Dharmandar

To reverse a string in Python, you can use the built-in function slice notation ([::-1]), or the join() method with list reversal:nnExample using slice notation:nninput_string = 'Hello World!'nreversed_string = input_string[::-1]nprint(reversed_string)nnExample using list and join():nninput_list = list(input_string)ninput_list.reverse()nreversed_string = ''.join(input_list)nprint(reversed_string)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Do monkeys sleep at night?

1 Answers  


What data hiding techniques?

1 Answers  


Which one is easier r or python?

1 Answers  


In Python what are iterators?

1 Answers  


Does python support switch or case statement in Python? If not what is the reason for the same?

1 Answers  


Differentiate between Pyramid, Django, and Flask

2 Answers  


Python read a single character from the user?

1 Answers  


What is the python interactive console or python shell?

1 Answers  


How can you get the google cache age of any url or web page?

1 Answers  


When would you use a list vs. A tuple vs. A set in python?

1 Answers  


Tell me what's the process to get the home directory using ‘~' in python?

1 Answers  


What is python shell and idle?

1 Answers  


Categories