Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to check for palindromes in python

def is_palindrome(s):
  reverse = s[::-1]
  if (s == reverse):
    return True
  return False

s1 = 'racecar'
s2 = 'hippopotamus'

print(''racecar' a palindrome -> {}'.format(is_palindrome(s1)))
print(''hippopotamus' a palindrome -> {}'.format(is_palindrome(s2)))


# output

# 'racecar' is a palindrome -> True
# 'hippopotamus' is a palindrome -> False
Source by www.kdnuggets.com #
 
PREVIOUS NEXT
Tagged: #How #check #palindromes #python
ADD COMMENT
Topic
Name
1+4 =