首页 > 编程语言 > 详细

python:missing 1 required positional argument: 'self' 的error

时间:2020-07-07 16:43:34      阅读:70      评论:0      收藏:0      [点我收藏+]

问题描述:

class test:
    def test01(self):
        pass

if __name__ == "__main__":
    test.test01()

如上代码执行时会报错:missing 1 required positional argument: ‘self‘ ,问题原因如下:

对象的声明需要括号。而类的声明括号可有可无

定义在自定义类中的方法需要一个默认的self参数。错误提示没有self 就是说明这个类的对象没有创建成功。

 

修改后的代码片段:

 

if __name__ == "__main__":
    test().test01()

 

 

本文转载自:https://www.cnblogs.com/walterwsj/p/11627439.html

 

python:missing 1 required positional argument: 'self' 的error

原文:https://www.cnblogs.com/jinziguang/p/13261404.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!