Справедливое замечание, JOHN_16.
class SuperStr(str):
def __init__(self,name):
self.name=name
def is_repeatance(self,s):# метод определяет состоит ли объект из n
if isinstance(self.name,str) and isinstance(s,str):# повторов строки s
self.name=self.name.lower()
self.s=s.lower()
if self.s!='' and self.name!='' and len(self.name)>=len(self.s)\
and len(self.name)%len(self.s)==0\
and self.s*(len(self.name)/len(self.s))==self.name:
return True
else: return False
else: return False
def is_palindrom(self):# метод определяет является ли объект палмндромом
if str(self.name)==self.name:
if self.name=='' or self.name.lower()==self.name[::-1].lower():
return True
else: return False
else: return False
#******************************** TEST ***************************
print '*************** S ***************'
s=SuperStr('123123123123')
print s.is_repeatance('123'), '=', 'True'
print s.is_repeatance('123123'), '=', 'True'
print s.is_repeatance('123123123123'), '=', 'True'
print s.is_repeatance('12312'), '=', 'False'
print s.is_repeatance(123), '=', 'False'
print s.is_palindrom(), '=', 'False'
print s, '=', '123123123123'
print int(s), '=', 123123123123
print s + 'qwe', '=', '123123123123qwe'
p = SuperStr('123_321')
print p.is_palindrom(), '=', True
print '*************** S1 ***************'
s1 = SuperStr('678678678678')
print s1.is_repeatance('6786'), '=', 'False'
print s1.is_repeatance('678'), '=', 'True'
print s1.is_repeatance('678678'), '=', 'True'
print s1.is_repeatance('678678678'), '=', 'False'
print s1.is_repeatance('q'), '=', 'False'
print s1.is_repeatance(''), '=', 'False'
print s1.is_repeatance(678), '=', 'False'
print s1.is_repeatance([]), '=', 'False'
print s1.is_repeatance([678]), '=', 'False'
print s1.is_palindrom(), '=', 'False'
print s1.isdigit(), '=', 'True'
print int(s1), '=', '678678678678'
print '("' + s1 + '")', '=', '("678678678678")'
print '*************** S2 ***************'
s2 = SuperStr('')
print s2.is_repeatance(''), '=', 'False'
print s2.is_repeatance('a'), '=', 'False'
print s2.is_palindrom(), '=', 'True'
print bool(s2), '=', 'False'
s3 = SuperStr('mystring1Gnirtsym')
print s3.is_repeatance('my'), '=', 'False'
print s3.is_repeatance('q,.%;#'), '=', 'False'
print s3.is_palindrom(), '=', 'True'
print s3.lower(), '=', 'mystring1gnirtsym'
print s3, '=', 'mystring1Gnirtsym'
print '*************** S4 ***************'
s4 = SuperStr('q')
s4.is_repeatance(''), '=', 'False'
print s4.is_repeatance('q'), '=', 'True'
print s4.is_palindrom(), '=', 'True'
print s4.upper(), '=', 'Q'