金宝汇百丽宫影城,惊哗春梦,叶选平儿子
例如一个类
class foo(object): def __init__(self): print(1) def __new__(self): print(2) #2
class foo(object): def __init__(self): print(self) print(1) def __new__(self): print(2) return 2
class foo(object): def __init__(self): print(self) print(1) def __new__(cls): print(2) return object.__new__(cls) ''' 2 <__main__.foo object at 0x000000000213c278> 1 '''
当我们想要一个具有参数的的新类的时候
class demo(object): def __init__(self,name): self.name = name def __new__(cls, *args, **kwargs): return object.__new__(cls)
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论