class Student1: # 定義類的相同屬性 school = 'xiwangzhongxue' count = 0 aaa = 10 # 定義類的相同方法 # 定義類的屬性方法 def __init__(self,name,age): self.name = name self.age = age Student.count += 1 self.aaa = 1 def choice(self): print('選課...') def study(self): print('學習....')
print(Student.count)
0python
stu1 = Student('小明',18) print(stu1.count)
1學習
stu2 = Student('小紅',20) print(stu2.count)
2code
print(Student.count)
2對象
print(stu1.name)
小明it
print(stu1.count) print(stu2.count)
2class
2程序
print(stu1.__dict__)
{'name': '小明', 'age': 18, 'aaa': 1}方法
print(stu2.__dict__)
{'name': '小紅', 'age': 20, 'aaa': 1}dict