【发布时间】:2014-01-24 16:51:52
【问题描述】:
我有一个类有这两种方法:
def whatIsYourName(self):
print 'my name is class A'
def whatIsYourName(self, name):
print 'my name is {0}, I am class A'.format(name)
我可以打电话给第二个。但是当我这样称呼第一个时:
x = myClass()
x.whatIsYourName()
我收到了这个错误:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
TypeError: whatIsYourName() takes exactly 2 arguments (1 given)
我使用的是 python 2.7
【问题讨论】:
标签: python-2.7