To Check whether the String is Palindrome or not. - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Wednesday, June 10, 2020

To Check whether the String is Palindrome or not.




Question

To Check whether the String is Palindrome or not.

Sample TestCase Expected Output

1. MalayalamYes


2. PythonNo 


Answer


def isPalindrome(s): 
    return s == s[::-1] 
s = input("Enter a string:")
ans = isPalindrome(s) 
  
if ans: 
    print("Yes") 
else: 
    print("No") 


Here, the term s[::-1] is to reverse the given string. 

Follow Us For More...


No comments:

Post a Comment