Conteúdo do Curso
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
Using Packing and Unpacking for Efficient Code in Python
The most common usage of packing and unpacking can be seen in the following examples.
Values Swapping
Typically, to swap the values of variables, you might use an additional temporary variable:
Simply put, unpacking enables you to swap values between variables in a more concise manner:
Dropping Unneeded Values
If you only need the first values from an iterable object, you can pass the unneeded values to the *_ variable.
Note
We use '_' single underscore for ignoring values: It's common to use _ as a throwaway variable to indicate that a specific value in a tuple unpacking is intentionally being ignored.
1. What is the value of 'c' after it is executed?
2. What does the following code snippet accomplish?
3. What is the result of the following Python code?
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 1. Capítulo 3