python - 如何从班级讲师访问班级学生的变量?
问题描述
我想st()
退回student
's 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())
结果:
['david', 'nick']
[]
解决方案
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())
我希望它会帮助你。
推荐阅读
- impala - 我想向 Impala Query 中的现有表添加两个列名
- android - 如何在无法直接访问 View Class 的地方添加 Snackbar
- ruby-on-rails - Ruby:无法通过 Bundler 安装 gem
- r - 在 mutate (dplyr) 中创建新的列
- selenium - 我在 selenese runner java 中遇到错误
- excel - 以月计算日期重叠
- json - 从 json 中提取 | jq 由一个给定的单词
- ruby-on-rails - 根据两列对记录进行排序
- amazon-web-services - 我可以限制互联网网关的 IP 范围吗?
- c# - 需要获取 IEDriverServer.exe 的进程 ID,以便我可以获取浏览器的子 PID