0
Q:

string palindrome in python

# using slicing
def is_palindrome(s):
  return s==s[::-1]

#===========
#using reversed()

# Program to check if a string is palindrome or not
my_str = 'aIbohPhoBiA'
# make it suitable for caseless comparison
my_str = my_str.casefold()
# reverse the string
rev_str = reversed(my_str)
# check if the string is equal to its reverse
if list(my_str) == list(rev_str):
   print("The string is a palindrome.")
else:
   print("The string is not a palindrome.")
    
#=============
#solve iteratively

def check_palin(word):
    for i in xrange(len(word)/2):
        if word[i] != word[-(i+1)]:
            return False
    return True
5
def check_if_palindrome(s):
  return s == s[::-1]
3
mes=input("Enter the word and see if it is palindrome ")
if mes==mes[::-1]:
    print("This word is palindrome")
else:
    print("This word is not palindrome")
1
checking palindrone program
0

New to Communities?

Join the community