I wish to learn more about the rev_string
I tried to see if "MOM" is a palindrome and I wanted the result to be yes/no
I wish to learn more about the rev_string
I tried to see if "MOM" is a palindrome and I wanted the result to be yes/no
It's very simple, First, you need to reverse the String
that you want to check whether it's a palindrome or not. Then Compare the reverse String
with the input one. If it's the same then it's a palindrome else it's not.
string = "MoM"
revstring = "".join(reversed(string))
print("Yes" if string == revstring else "No")
s=input()
if s==s[::-1]:
print("Yes")
else:
print("No")
Explanation:
In line 1 we have taken a string "s" as an input. Reverse of s is given by slicing by s[::-1]. Then from line 2 a block of code executes and check if "s" is a palindrome or not.