#python中构造函数只能出现一次,通过默认参数实现函数重载
class person:
def __init__(self,n="",g="",a=0):
self.name=n
self.gender=g
self.age=a
def show(self):
print(self.name,self.gender,self.age)
a=person("james")#error
b=person("james","female")
c=person("james","male",20)#构造属性为实例的,不是类的
a.show()
b.show()
c.show()
python基础复习(11)--python中构造函数只能出现一次,通过默认参数实现函数重载
最新推荐文章于 2022-08-06 22:31:56 发布