Anatomy: Default Parameters Abstraction
Functions can have optional parameters with default values. Click each part of this definition to see how it works.
# Increase power level
Identify all 9 parts!
Spot the Keyword Argument
You can pass arguments by position or by name (keyword). Click on the argument(s) below that are passed using the parameter_name=value syntax (keyword arguments).
def create_profile(user_id, active=True): ...
Simulator: Defaults & Keywords Abstraction
Below is a function `configure_system` with default parameters. Your task: Call this function to set the `retries` parameter to `5`, but let `timeout` use its default value.
print(f"Mode: {mode}, Timeout: {timeout}, Retries: {retries}")
Advanced Mini Missions! Decomposition
Combine your knowledge of defaults and keywords to solve these challenges.
Mission 1: Greeting with Default
Define a function `greet_user(name, greeting="Hi")`. Then, call it once just with the name `"Alex"` (using the default greeting).
Mission 2: Keyword Power
A function `set_config(ip_address, port=80, protocol="http")` exists. Call this function providing `"192.168.1.100"` for `ip_address` and `"https"` for `protocol` using keyword arguments (let `port` use its default).
Mission 3: Flexible Plotting
Define `plot_data(data, color="blue", linestyle="-")`. Call it twice: first with just `my_data` (imagine this variable exists). Second time, call it with `my_data`, setting `color` to `"red"` using a keyword argument.
Module 17 Advanced Practice Complete!
You've mastered defaults and keywords, making your function calls much more flexible! Great job stepping up the complexity. Abstraction