下面程序的输出结果是( )。class Student: count = 0 def __init__(self, name): self.name = name Student.count += 1s1 = Student("Alex")s2 = Student("Jack")print(s1.count)
举一反三
- 以下有关类的声明,正确的是 A: class Student(object) def __init__(self, name, score): self.name = name self.score = score B: class Student(object) def __init__(self, name, score) self.name = name self.score = score C: class Student(object): def __init__(self, name, score): self.name = name self.score = score D: class Student(object): def __int__(self, name, score): self.name = name self.score = score
- 写出输出结果:class Student: def __init__( self, name,age=18): self.name=name self.age=agestudent=Student("李强",21)print(student.age)
- 以下代码中,实例方法定义正确的是() A: class Student: def setName(self,name): self.name=name B: class Student: def setName(name): self.name=name C: class Student: def setName(self): self.name=name D: class Student: def setName(name,self): self.name=name
- class Person: def __init__(self,n="xxx"): self.name=n class Student(Person): def __init__(self,s="male"): self.sex=s def show(self): print(self.name,self.sex) s=Student("female") s.show() 结果:
- class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") s.show() 结果