Python program to check if a string is palindrome or not


Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if reverse of the string is same as string. For example, “radar” is palindrome, but “radix” is not palindrome.


Input : malayalam
Output : Yes

Input : geeks
Output : No

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

# function which return reverse of a string
def reverse(s):
    return s[::-1]

def isPalindrome(s):
    # Calling reverse function
    rev = reverse(s)

    # Checking if both string are equal or not
    if (s == rev):
        return True
    return False

# Driver code
s = "malayalam"
ans = isPalindrome(s)

if ans == 1:

Output :


This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:

1 Average Difficulty : 1/5.0
Based on 3 vote(s)

Writing code in comment? Please use, generate link and share the link here.