标签:结果 div col 系统调用 结构 nbsp info 实例 完整
22.类
# 类 class # 实例 实体 instance class Student: # 空语句 保持结构的完整性 pass jack = Student() jack.name = "Song Ke" print(jack.name) pony = Student() pony.name = "pony" print(pony.name)
run结果:
23.构造函数
# 构造函数 constructor class Student: # 声明构造函数 系统调用的 def __init__(self, name, age, sex): self.name = name self.age = age self.sex = sex print("__init__ is run") jack = Student("jack.a", 21, "男") pony = Student("pony.b", 22, "女") print(jack.name, jack.age, jack.sex) print(pony.name, pony.age, pony.sex)
run结果:
标签:结果 div col 系统调用 结构 nbsp info 实例 完整
原文地址:https://www.cnblogs.com/songxiaoke/p/11890425.html