标签:erro color int ack style can ipy class 函数
书中对类定义下的函数有如下例子
class Dog: #dog can bark def bark(slef): print("wang") pass pass zhubite=Dog() zhubite.bark()
出于好奇,去掉slef之后代码变成如下内容
class Dog: #dog can bark def bark(): print("wang") pass pass zhubite=Dog() zhubite.bark()
显示报错内容为:
TypeError Traceback (most recent call last) <ipython-input-11-264f1f6ba156> in <module> 1 zhubite=Dog() ----> 2 zhubite.bark() TypeError: bark() takes 0 positional arguments but 1 was given
class 类下定义的函数需要self
标签:erro color int ack style can ipy class 函数
原文地址:https://www.cnblogs.com/yuvejxke/p/12337030.html