Saturday, January 28, 2017

String Palindrome or Not Python

Tags

Question::

Define a function reverse() that computes the reversal of a string. For example, reverse("I am testing") should return the string "gnitset ma I".

Code::
def reverse(l):
    return"".join(l[i] for i in range(len(l)-1,-1,-1)) 
name=input("Enter String:")
rev=reverse(name)
print("Reverse is:",rev)
if(rev==name):
    print("String is Palindrome")
else:

    print("Not a Palindrome")

Output::