

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of functions in Python with a focus on keyword arguments, default arguments, and recursion. Keyword arguments are specified by parameter name, while positional arguments are assigned based on their position in the argument list. Default arguments provide optional parameters with default values. Recursion is a method of problem solving where a problem is broken down into similar sub-problems until they can be directly solved. examples and exercises.
Typology: Slides
1 / 33
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