

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























Default Arguments in Python
>>> def f(a, b=2, c=3): print(a, b, c)
>>> f(1) # Use defaults 1 2 3 >>> f(a=1) 1 2 3 >>> f(1, 4) # Override defaults 1 4 3 >>> f(1, 4, 5) 1 4 5
>>> f(1, c=6) # Choose defaults 1 2 6 Combining keywords and defaults def func(spam, eggs, toast=0, ham=0):
print((spam, eggs, toast, ham))
>>> def f(a, *pargs, **kargs): print(a, pargs, kargs) >>> f(1, 2, 3, x=1, y=2) 1 (2, 3) {'y': 2, 'x': 1}
>>> def func(a, b, c, d): print(a, b, c, d) >>> args = (1, 2) >>>args += (3, 4) >>> func(*args)
1 2 3 4
Different patterns in Algorithm
Recursive algorithms