-1

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

  • 1
    I search first: https://stackoverflow.com/a/28118244/1766544 although I would prefer iterators and just compare s vs reversed(s) one character at a time – Kenny Ostrom Nov 30 '22 at 02:19
  • Does this answer your question? [How to check for palindrome using Python logic](https://stackoverflow.com/questions/17331290/how-to-check-for-palindrome-using-python-logic) – Gino Mempin Nov 30 '22 at 04:28

2 Answers2

2

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")
Muntasir Aonik
  • 1,800
  • 1
  • 9
  • 22
0
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.