码迷,mamicode.com
首页 > 其他好文 > 详细

takes 3 positional arguments but 4 were given错误

时间:2017-11-29 14:43:44      阅读:1045      评论:0      收藏:0      [点我收藏+]

标签:错误   blog   方法   argument   参数   python   osi   创建   self   

之前写程序经常会碰到此类问题,确认发现并没有少参数。后来恍然大悟:函数为类下函数,定义时需要添加self参数。

但是!但是!为何Python给self赋值而你不必给self赋值?

创建了一个类MyClass,实例化MyClass得到了MyObject这个对象,
然后调用这个对象的方法MyObject.method(arg1,arg2),
这个过程中Python会自动转为Myclass.mehod(MyObject,arg1,arg2)。

takes 3 positional arguments but 4 were given错误

标签:错误   blog   方法   argument   参数   python   osi   创建   self   

原文地址:http://www.cnblogs.com/everfight/p/python_class.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!