How to reverse a string?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to reverse a string??

6th Dec 2020, 8:32 AM
Harshita Sharma
Harshita Sharma - avatar
5 Answers
+ 7
StringName=StringName[::-1] :-)
6th Dec 2020, 8:38 AM
Lae
+ 7
print("".join(reversed(input()))) or print(input()[::-1])
6th Dec 2020, 10:04 AM
David Ashton
David Ashton - avatar
+ 5
It is better is to collect your substrings in a list, and join them later: def reverse_a_string_more_slowly(a_string): new_strings = [] index = len(a_string) while index: index -= 1 new_strings.append(a_string[index]) return ''.join(new_strings) Though it's simple that when you'll learn about index you will get it easily! In simple language you can just use (-1) to reverse the input..
6th Dec 2020, 9:35 AM
Piyush
Piyush - avatar
+ 1
Thanks
6th Dec 2020, 8:38 AM
Harshita Sharma
Harshita Sharma - avatar
+ 1
Thank you all..
6th Dec 2020, 10:08 AM
Harshita Sharma
Harshita Sharma - avatar