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