forked from peiss/ant-learn-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.py
More file actions
50 lines (39 loc) · 886 Bytes
/
Copy pathstudent.py
File metadata and controls
50 lines (39 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Student:
"""
学生类
"""
# 类变量,学生的数目
total_cnt = 0
def __init__(self, name, age):
"""
初始化方法
:param name: 姓名
:param age: 年龄
"""
self.name = name
self.age = age
Student.total_cnt += 1
def set_grade(self, grade):
"""
设定学生的成绩
:param grade:
:return:
"""
self.grade = grade
def print_info(self):
"""
打印学生的信息
:return:
"""
print("sutdent info", self.name, self.age, self.grade)
# 创建两个类的实例
s1 = Student("xiaoming", 20)
s2 = Student("xiaowang", 25)
# 打印类变量
print(Student.total_cnt)
# 设定学生的成绩
s1.set_grade(100)
s2.set_grade(99)
# 调用Print的普通函数
s1.print_info()
s2.print_info()