0
How to reverse a string in python
2 Answers
+ 1
hello,Deepak Ghodinde
Strings can be reversed using slicing. To reverse a string,
we simply create a slice that starts with the length of the string, and ends at index 0.
To reverse a string using slicing, write:
stringname[stringlength::-1]
or
stringname[::-1]
you can also reverse string using join
str="Python"
reversedstring=''.join(reversed(str))
i hope this will help to you
+ 2
Variable_name="Hello World"[ : : -1]
Where you can replace Hello World with your own string
What it does is it starts from the end position of string extracts a character and reduce the value by -1