class Student:def __init__(self,name,age):self.name=nameself.age=agedef fun1(self):print("hello")( )def fun2(self):print("yes")child=Child("Tom",20)child.fun1()
举一反三
- 写出输出结果:class Student: def __init__( self, name,age=18): self.name=name self.age=agestudent=Student("李强",21)print(student.age)
- 以下有关类的声明,正确的是 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,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") s.show() 结果
- 以下代码编译后,调用错误的是:class Student: def __init__(self,name,age): self.name=name self.age=age def __del__(self): del self.name del self.age print("对象数据删除完毕!")stu=Student("zs",10) A: stu.name; B: stu.__init__("李四",20); C: del stu; D: stu.__del__();
- 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() 结果: