Understanding def foo(*args)

Mel mwilson at the-wire.com
Sun Jan 30 14:40:29 EST 2011


sl33k_ wrote:
> Hi,
>> I am struggling to grasp this concept about def foo(*args). Also, what
> is def bar(*args, *kwargs)?
>> Isnt it like self must be the first parameter to the method/function?
> If not what are the exceptions?
>> Also, can the terms method and function be used interchangeably?
>> TIA

Try
def foo (*args):
 print 'foo args:', repr (args)
foo (1, 2, 3, 4)
def bar (*args, **kwargs):
 print 'bar args:', args
 print 'bar kwargs:', kwargs
bar (1, 2, 3, 4)
bar (1, 2, 3, baz=6, boz=None)
	Mel.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /