Four different ways to pass parameters : Function Parameters « Function « Python






Four different ways to pass parameters

Four different ways to pass parameters

def echo(*args, **kwargs): print args, kwargs

print echo(1, 2, a=3, b=4)



pargs = (1, 2)
kargs = {'a':3, 'b':4}
print apply(echo, pargs, kargs)



print apply(echo, args)              # traditional: tuple

print func(*args)                    # new apply-like syntax

print echo(*pargs, **kargs)          # keyword dictionaries too

print echo(0, *pargs, **kargs)       # normal, *tuple, **dictionary

           
       








Related examples in the same category

1.Passing value or passing addressPassing value or passing address
2.Pass string value into a functionPass string value into a function
3.Python functions are 'typeless'Python functions are 'typeless'
4.Pass immutable and mutable value into functionPass immutable and mutable value into function