Does python support multi prototype.

Chris Dutton rubyguru at hotmail.com
Wed Aug 4 04:17:11 CEST 2004


angel wrote:
> Hi
> 
> Java and cpp support one function name multi function prototype.
> For example:
> A:
> int func1(String s){}
> int func1(int i){}
> 
> B:
> int func1(String s){}
> int func1(String s, int i){}
> 
> Does python support it?

No, but it doesn't have to.  The type of a function's arguments are not 
statically limited.

def foo(bar):
    print bar

I can call this as easily with one type as with another:

foo(1)
foo("baz")

As for the number of arguments a function takes, it's possible to use 
the * operator to slurp extra arguments up into a list.

def foo(bar, *extras):
    ...

foo(1)
foo("baz")
foo("baz", "hello", "world")



More information about the Python-list mailing list