Course Content
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
Challenge: Basic Smores Recipe
Task
Swipe to start coding
When you run this script, it should output the layers of a smore in the correct order: cracker, chocolate, marshmallow, cracker.
This exercise demonstrates the concept of how decorators wrap functionality around a function in Python.
- In the wrapper function of the
crackers
decorator, you need to call the function being decorated (i.e.,func
). This should be done between the two print statements; - Ensure that the function func is called with any arguments and keyword arguments it might receive;
- Similar to the crackers decorator, the chocolate decorator should call the function it's decorating.
- The main task is to put decorators in right sequence. You must receive:
Solution
Everything was clear?
Thanks for your feedback!
Section 5. Chapter 6
Challenge: Basic Smores Recipe
Task
Swipe to start coding
When you run this script, it should output the layers of a smore in the correct order: cracker, chocolate, marshmallow, cracker.
This exercise demonstrates the concept of how decorators wrap functionality around a function in Python.
- In the wrapper function of the
crackers
decorator, you need to call the function being decorated (i.e.,func
). This should be done between the two print statements; - Ensure that the function func is called with any arguments and keyword arguments it might receive;
- Similar to the crackers decorator, the chocolate decorator should call the function it's decorating.
- The main task is to put decorators in right sequence. You must receive:
Solution
Everything was clear?
Thanks for your feedback!
Section 5. Chapter 6