小编use*_*269的帖子

python中的方法重载

我需要调用unparameterised方法first,但也参数化first,但它给出了一个错误.

>>> class A:
...     def first(self):
...             print 'first method'
...     def first(self,f):
...             print 'first met',f
...
>>> a=A()
>>> a.first()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: first() takes exactly 2 arguments (1 given) 
Run Code Online (Sandbox Code Playgroud)

是否可以像在Java中一样在Python中执行方法重载?

python overloading

9
推荐指数
3
解决办法
1万
查看次数

标签 统计

overloading ×1

python ×1