>>> class CapStr(str):
def __new__(cls,string):
string = string.upper()
return str.__new__(cls,string) >>> a = CapStr('afsgdfqwehu7348')
>>> a
'AFSGDFQWEHU7348'
__new__方法首先调用并返回一个实例化对象
2021-12-18 03:03:06
>>> class CapStr(str):
def __new__(cls,string):
string = string.upper()
return str.__new__(cls,string) >>> a = CapStr('afsgdfqwehu7348')
>>> a
'AFSGDFQWEHU7348'
__new__方法首先调用并返回一个实例化对象