我希望st()
返回student
的{{1}}。
但是为什么我会得到空的name
?
如何在list
类中获得student
类的名称?
lecturer
结果:
class student:
def __init__(self,*name):
self.name=list(name)
def stud(self):
return self.name
stu=student("david","nick")
print(stu.stud())
class lector(student):
def st(self):
return self.name
lec=lector()
print(lec.st())
答案 0 :(得分:0)
1)。类call()
中没有lector
函数。
2)。我已经修改了您的代码以获得结果:-
class student:
def __init__(self,*name):
student.name=list(name)
def stud(self):
return student.name
stu=student("david","nick")
print(stu.stud())
class lector(student):
def __init__(self): # Now you can access the variable which are inside student classs
super
def st(self):
return lector.name
lec=lector()
print(lec.st())
希望它能对您有所帮助。