python在实例化一个对象的时候会调用__init__方法,但是在调用__init__方法之前会调用__new__方法,
__new__方法是python类的构造方法,我们可以通过下面的代码创建将字符串全部转为大写的类。
class UpperStr(str):
def __new__(cls, string=""):
return str.__new__(cls, string.upper())
hello = UpperStr("hello world!")
print(hello)