Python,*args,**kwargs参数有点像c语言的main函数传参
class demoClass:
instances_created = 0
def new(cls1,*args,**kwargs):
print(“new():”,cls1,args,kwargs)
instance = super().new(cls1)
instance.number = cls1.instances_created
cls1.instances_created += 1
return instance
def init(self,aa,bb,cc,dd,ss):
pass
# print(“init():”,self,attribute)
# self.attribute = attribute
test1 = demoClass(“abc”, [“bb”,‘ww’], ‘cc’, ‘dd’,‘ss’)
test2 = demoClass(“xyz”, “bb”, ‘cc’, ‘dd’,‘ss’)
#test3 = demoClass(“xyz1”, “bb”)
print(test1.number,test1.instances_created)
print(test2.number,test2.instances_created)
有点像C语言的main函数传参
最新推荐文章于 2024-09-01 16:57:39 发布