你需要在 student.py
中编写 Student
类的构造方法完成类的初始化,并且补全speaking函数打印出要求的信息:
1.根据构造函数的接收参数传入学生的姓名 name
2.调用学生类的 speaking()
函数,要求能打印出对应的字符串,像这样:Hello, My name is John , there are 1 students in total!
# -- write your code here --
class Student:
count = 0
def __init__(self, name):
global count
self.name = name
Student.count += 1
def speaking(self):
# print something like `Hello, My name is John , there are 1 students in total!`
# -- write your code here --
print("Hello, My name is {} , there are {} students in total!".format(self.name,Student.count))
注意点:
1.format()的前面是“.”,而不是“,”
2. 类里面直接定义的变量,且不是在函数内的,可以当作这个类的全局变量,直接“类名.变量名”使用