It is quite simple in Python, it can be done easily using step parameter of
string extract
>>> str =
'reverse'
>>> str[::-1]
'esrever'
With the help of step = -1, we can easily reverse any string in python.
Lets create a function, which will reverse the given string and then
check if reverse = actual then return true else false.
def reverseStr(str):
if str[::-1] == str:
print('The result is True')
else:
print('The result is False')
str = 'liril'
reverseStr(str)
if str[::-1] == str:
print('The result is True')
else:
print('The result is False')
str = 'liril'
reverseStr(str)
Output:
True
So here you can assign str with value ‘liril’ which in turn is passed to
the function and the result was equal to the reverse of the string passed
that’s why the result was true.
Data Science with…Python J
Post Reference: Vikram Aristocratic Elfin Share
No comments:
Post a Comment