单选题 适中
#5603

运行以下Python代码,结果是?( ) class Person ( ) : def __init__ ( self , name , age ) : sel…

运行以下Python代码,结果是?(   )

class Person():
    def __init__(self, name, age):
        self.name = name
        self.age = age
    def say_hello(self):
        print(f"Hello, my name is {self.name}. I am {self.age} years ol")
person1 = Person("Alice", 25)
person2 = Person("Bob", 30)
person1.say_hello()
未登录也能判分,登录后才会记录
答案与解析
正确答案:A
解析

代码中,定义了一个名为Person的类。这个类有一个初始化方法__init__,用于设置实例的属性name和age。还有一个类方法say_hello,用于打印实例的名字和年龄。然后,创建了两个Person类的实例person1和person2,并通过调用实例的方法say_hello来输出实例person1的信息。