[Tutor] question about *args and functions

Andre Engels andreengels at gmail.com
Fri Jan 26 16:41:00 CET 2007

2007/1/26, shawn bright <nephish at gmail.com>:
> lo there all,
> if i have a function that sometimes needs a value passed to it and
> sometimes not, is this where i use *args ?

No. *args is used if there are arguments that could occur more than once.

like this
> def some_function(req_var, req_var2, un_req_var):
>     do some stuff
>     return value
> how would i use this if sometimes i need to process un_req_var and
> sometimes not ?

def some_function(req_var, req_var2, un_req_var = None):
    do some stuff
    return value

Now, the function can be called both with and without un_req_var, and if it
is called without un_req_var, within the function body un_req_var is
considered to be None.

Andre Engels, andreengels at gmail.com
ICQ: 6260644  --  Skype: a_engels
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070126/9adc05a4/attachment.htm 

More information about the Tutor mailing list