Python program to check if a string is palindrome or not

 


Palindrome :

               A string is said to be palindrome if the reverse of the string is the same as string. 

Examples:

Input : malayalam
Output : Yes

Input : geeks
Output : No


Algorithm :

  1. Find reverse of string
  2. Check if reverse and original are same or not
Program :


def isPalindrome(s):
    return s == s[::-1]
 
 
# Driver code
s = "malayalam"
ans = isPalindrome(s)
 
if ans:
    print("Yes")
else:
    print("No")

Output:
Yes

Post a Comment

0 Comments