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
A: xxx male
B: xxx
C: 结果错误
D: xxx female
举一反三
- 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 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: 张三
- 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,n="xxx"): self.name=n def show(self): print(self.name)s=Student("yyy")s.show()结果 A: yyy B: xxx C: None D: 错误
- 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) 结果: