举一反三
- class Student: def __init__(self,n="xxx",s="男"): self.name=n self.sex=s def show(self): print(s.name,s.sex) s=Student("yyy") Student.show(s) 结果:
- 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",s="男"): self.name=n self.sex=s def show(self): print(s.name,s.sex)s=Student("yyy")Student.show(s)结果: A: yyy 男 B: xxx 男 C: Student.show(s)错误 D: def __init__(self,n="xxx",s="男")错误
- class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name) s=Student("yyy") s.show() 结果
- class Person:def __init__(self,n="xxx"):self.name=nclass Student(Person):def __init__(self,s="male"):self.sex=sdef show(self):print(self.name,self.sex)s=Student("female")s.show()结果: A: xxx male B: xxx C: 结果错误 D: xxx female
内容
- 0
class Student: def __init__(self,n="xxx"): self.name=n def show(self): print(self.name)s=Student("yyy")s.show()结果 A: yyy B: xxx C: None D: 错误
- 1
下面程序运行的结果是( )。class Person:def __init__(self,n="张三"): self.name=nclass Student(Person):def __init__(self,s="male"):self.sex=sdef show(self):print(self.name,self.sex)s=Student("female")s.show() A: 张三 male B: 张三 female C: 出错 D: 张三
- 2
class Student: def __init__(self,n="xxx",s="男"): self.name=n self.sex=s def show(self): print(s.name,s.sex,s.age)s=Student("yyy")s.age=20s.show()结果: A: yyy 男 0 B: yyy 男 None C: yyy 男 20 D: 错误
- 3
class Student: age=20 def __init__(self,n="xxx",s="男"): self.name=n self.sex=s def show(self): print(s.name,s.sex,s.age)s=Student("yyy")s.age=30s.show()结果: A: yyy 男 20 B: yyy 男 30 C: xxx 男 30 D: xxx 男 20
- 4
以下有关类的声明,正确的是 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