Functions, Operators, and Overloading?

Stefan Behnel stefan.behnel-n05pAM at web.de
Mon Jul 24 14:05:53 EDT 2006


Gerhard Fiedler schrieb:
> On 2006-07-24 14:30:31, Brian Beck wrote:
> 
>> Michael Yanowitz wrote:
>>>    Maybe I am missing something, but from what I've seen,
>>> it is not possible to overload functions in Python. That
>>> is I can't have a
>>>   def func1 (int1, string1):
>>>    and a
>>>   def func1 (int1, int3, string1, string2):
>>>     without the second func1 overwriting the first.
>> Correct.
> 
> Can you write a function that accepts any number of arguments? And then
> branch based on the number of arguments supplied?
> 
> I guess you can do that with a list as only argument. But can that be done
> using the "normal" function argument notation?

I guess you mean something like

   func1(int1, arg2, *args):
       if len(args) == 2:
          ...
       elif not args:
          ...
       else:
          raise ...


Stefan



More information about the Python-list mailing list