构造函数二

 1 class Person():
 2     # def __init__(self):
 3     #     print("init1")
 4     #
 5     # def __init__(self):
 6     #     print("init2")
 7 
 8     def __init__(self, name, age=0, sex=0, **kwargs):
 9         # self.name = name
10         print("init3")
11         self.name = name
12         self.age = age
13         self.sex = sex
14         self.weight = kwargs.get("weight")
15         print(name, age, sex, kwargs)
16 
17 per1 = Person("lily")
18 per2 = Person("lll", 12)
19 per3 = Person("iii", 12,34)
20 per4 = Person("ooo", 34, 45, w=1)
21 per5 = Person(name="ppp", sex=88)

 

posted @ 2019-07-30 20:19  巨菜的小鸟  阅读(95)  评论(0编辑  收藏  举报