python 类
(正确方式)
>>> class a():
def b(self):
print "ok"
>>> c = a()
>>> c.b()
ok
(错误方式)
>>> class a():
def b(self):
print "ok"
>>> a.b()
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
a.b()
TypeError: unbound method b() must be called with a instance as first argument (got nothing instead)
>>> class a():
def b(self):
print "ok"
>>> c = a()
>>> c.b()
ok
(错误方式)
>>> class a():
def b(self):
print "ok"
>>> a.b()
Traceback (most recent call last):
File "<pyshell#66>", line 1, in <module>
a.b()
TypeError: unbound method b() must be called with a instance as first argument (got nothing instead)

浙公网安备 33010602011771号