python - function .. 接受 0 个位置参数,但给出了 1 个
问题描述
我是 Python 新手,我想练习一个父类和派生类。我想使用 super 将父函数调用到子类。但是我遇到了一些错误。代码是
class First:
def my_func():
print('first')
class Second(First):
def my_func1():
super().my_func()
print('second')
obj = Second()
obj.my_func1()
解决方案
class First:
def my_func(self):
print('first')
class Second(First):
def my_func1(self):
super().my_func()
print('second')
obj = Second()
obj.my_func1()
推荐阅读
- java - 如何转换列表
- powerquery - 在日和月值中添加前导零
- sql - 访问 VBA SQL:编写 WHERE 子句来比较本地和 ADO 远程连接数据
- python - Python - 调用另一个函数后如何返回上一个函数?
- c# - 随着时间的推移损坏区域代码不起作用,而使用与地面检查非常相似的代码是有效的?
- javascript - 如何将 vanilla js 获取代码转换为反应?
- woocommerce - 获取最近在 WooCommerce 中添加到购物车的产品的详细信息并触发 Google Analytics 添加到购物车事件
- mongodb - Mongodb:更新数据时“尝试在主机上运行命令'getlasterror'时出现网络错误”
- oracle - 通过其中一个扫描 ip 的数据库连接失败
- angular - Mat菜单总是出现在浏览器的左上角