I've written a piece of code to determine a typical palindrome string. I did this by the definition of a reverse() method returning a string. I am also eager to have the same method, but in the void form, because of some future needs.
As I add the latter to the code, the valid output will become invalid. Is it legal to define two methods with the same name, but different returning types?
If not, how can I write this code with the void-type method?
class detector(object):
def __init__(self,string):
self.string = string
forbidden = (' ','!','?','.','-','_','&','%',"#",",")
def eliminator(self):
for item in self.forbidden:
if item in self.string:
self.string = self.string.replace(item,"")
def reverse(self):
return self.string[::-1]
#def reverse(self):
# self.string = self.string[::-1] I am prone to add this method
def check(self):
reversed = self.reverse()
if self.string == reversed:
print("Yes")
else:
print("No")
det = detector("rise to vote, sir!")
det.eliminator()
det.check()
When I add the outcommented lines, the valid "Yes" becomes "No"!