Contenuti del Corso
Intermediate Python Techniques
Intermediate Python Techniques
1. Mastering Packing and Unpacking in Python
2. Mastering Function Arguments in Python
Python Function Arguments: Overview of Parameters and ArgumentsUsing *args in Python: Handling Variable-Length Positional ArgumentsChallenge: Calculating the Average Mark with *argsUsing **kwargs in Python: Flexible Keyword Arguments for Dynamic FunctionsChallenge: Mastering **kwargs in Python Functions
4. Understanding Variable Scope in Python
Global Variables in Python: Accessing and Modifying Global DataLocal Variables in Python: Understanding Function-Level ScopeChallenge: Modifying a Global Variable in PythonNested Functions in Python: Scope and AccessibilityNonlocal Variables in Python: Working with Enclosed ScopesPython Closures: Retaining State in Nested FunctionsChallenge: Implementing a Threshold Checker with Closures
5. Mastering Python Decorators
Introduction to Python DecoratorsPython Decorator Syntax: Writing and Applying DecoratorsChallenge: Create Your First Python DecoratorUsing Decorators with Parameters in PythonChaining Multiple Decorators: Advanced Function ModificationsChallenge: Basic Smores RecipePractical Examples of Python Decorator Usage in Real Applications
Python Function Arguments: Overview of Parameters and Arguments
First of all, let`s learn what positional, keyword, and optional arguments are.
def add(a, b, c):
return a + b + c
The example above uses positional arguments. If you pass a different number of arguments, an error will occur. To call the function add(1, 2, 3)
, you just pass the arguments by their positions. The positional argument is a mandatory one.
add(b=2, c=3, a=1)
Also, you can pass arguments using names. And there are keyword arguments. In this case, you do not need to follow the order of the arguments.
def add(a, b, c = 0): return a + b + c print(add(1, 2)) print(add(1, 2, 3))
After giving a default value to the argument, it becomes an optional one. So, you may pass it, and if not, the function will use the default value.
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 2. Capitolo 1