python - super() 什么时候需要参数才能正常工作?
问题描述
前任:
class Parent:
def name(self):
print("This is the parent method name()")
class Child(Parent):
def name(self):
super(Child, self).name()
super().name()
dad = Parent()
son = Child()
dad.name()
son.name()
Output:
This is the parent method name()
This is the parent method name()
This is the parent method name()
我很困惑为什么这在这两种情况下都能正常工作,我想知道什么时候必须在我的代码中使用 super(Child, self).name() 形式。任何帮助是极大的赞赏!
解决方案
推荐阅读
- azure - AZURE - 将 VM ARM 模板保存到模板
- ios - 在 SwiftUI 中使用 Introspect 隐藏 TabBar 时视图调整大小/扩展的底部
- java - javafx 项目中的 module-info.java 文件中的错误
- typo3 - TYPO3 v9.5 Extbase 错误处理与 routeEnhancers
- mysql - 我无法加载 http://localhost/phpmyadmin/
- kivy - 如何将文件 (.csv) 加载到 Beeware/Briefcase 应用程序中?
- android - 如何在 Android 中使用 ContentResolver 查询自定义文件夹中的图像/视频?
- go - 仅当地图中存在条目时才在 helm 模板中创建条目
- javascript - 如何读取 .txt 文件并将其显示在网页中?(使用快递)
- python - json.loads 不从 oidc 用户信息加载列表