Skip to content
mengfung.com
writing

PALINDROME

 ·  1 min read

Ruby:

class String
def palindrome?
self.downcase == self.downcase.reverse
end
end
p "Bob".palindrome?
p "andy".palindrome?

Python:

class myString(str):
def __init__ (self, value):
self.value = value
def is_palindrome(self):
return self.lower() == self[::-1].lower()
bob = myString("Bob")
andy = myString("andy")
print bob.is_palindrome()
print andy.is_palindrome()