定义类如下:class Test():def __init__(self,name):self.name=namedef show(self):print(self.name)下面代码能正常执行的是 ( )
A: t = Test('张三')t.show()
B: t = Test()t.show('张三')
C: t = Test()t.show()
D: t = Testt.show('张三')
A: t = Test('张三')t.show()
B: t = Test()t.show('张三')
C: t = Test()t.show()
D: t = Testt.show('张三')
举一反三
- 定义类的代码如下:class Person():def __init__(self,name):self.name=namedef show(self):print(self.name) A: p=Personp.show() B: p=Person()p.show('李思') C: p=Person('李思')p.show() D: p=Person('李思')show()
- 下面程序的运行结果是( )。class Student:def __init__(self,n="张三"):self.name=ndef show(self):print(self.name)stu=Student("李四")stu.show() A: 张三 B: 李四 C: 张三 李四 D: 李四 张三
- 定义类如下:class Hello(): def __init__(self,name): self.name=name def showInfo(self): print(self.name)下面代码能正常执行的 ( )。 A: h = Helloh.showInfo() B: h = Hello()h.showInfo('张三') C: h = Hello('张三')h.showInfo() D: h = Hello('admin')h.showInfo
- 下面程序运行的结果是( )。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() 结果