f(n=4) works; bug or feature?

Sean 'Shaleh' Perry shalehperry at attbi.com
Mon Dec 24 00:00:50 EST 2001


On 24-Dec-2001 Edward C. Jones wrote:
> In Python 2.2, the following code prints a "4".
> 
> def fun(n):
>      print n
> 
> fun(n=4)
> 
> Bug or feature?
> 

feature.  It is called a keyword argument.

def func(a, b, c):
        print a
        print b
        print c

func(b = 1, a = 8, c = 'hello')

The idea here is you can call the function with the arguments in any order as
long as you know their names.  Hnady for long function calls like gui toolkits
or network code.




More information about the Python-list mailing list