How to reverse a string in python?
By slicing it is easy as pie! The general format of string slicing is like below:
We do a little bit of a magic here and make step -1. -1 will read data from the end of the string to the first character and leave begin and end intact:
The output would be like below:
#python #string #slicing #step #reverse
By slicing it is easy as pie! The general format of string slicing is like below:
'YOUR_STRING'[begin : end : step]
We do a little bit of a magic here and make step -1. -1 will read data from the end of the string to the first character and leave begin and end intact:
'Hello'[::-1]
The output would be like below:
>>> 'hello'[::-1]
'olleh'
#python #string #slicing #step #reverse