第28846题 单选题
下列关于Python实例方法调用的描述中,正确的是哪一项?

已知如下Python代码:

class Student:
    def __init__(self, name):
        self.name = name
    def say_hello(self):
        return f"Hello, {self.name}"
stu = Student("Alice")
A

可以直接通过Student.say_hello()调用该实例方法,无需额外传参

B

通过实例stu调用say_hello()方法时,Python会自动将stu作为第一个参数传递给self形参

C

实例方法say_hello定义时不需要写第一个形参,调用时也不需要传参

D

若修改say_hellodef say_hello(self, msg):,则调用时需要同时传递selfmsg两个参数

程序运行统计
暂无判题统计
提交0次 正确率0.00%
答案解析