Back
+10 XP
Concept

Positional vs Keyword Arguments

Positional arguments match parameters in order. Keyword arguments pass explicitly by name `func(sound="woof", pet="dog")`, ignoring order.

python
def describe(pet, sound):
    print(f"The {pet} says {sound}!")

# Positional:
describe("cat", "meow")
# Keyword:
describe(sound="woof", pet="dog")

# 93. Positional vs Keyword Arguments Positional arguments match parameters in order. Keyword arguments pass explicitly by name `func(sound="woof", pet="dog")`, ignoring order: ```python def describe(pet, sound): print(f"The {pet} says {sound}!") # Positional (order matters): describe("cat", "meow") # Keyword (order is flexible): describe(sound="woof", pet="dog") ``` Golden rule: If you mix them, all positional arguments MUST come before any keyword arguments. `describe("cat", sound="purr")` is valid; `describe(pet="cat", "purr")` explodes.

Checkpoint

Can you pass keyword arguments in a different order than the function parameters?

Practice

Call `def make_box(width, height): return width * height` using keyword arguments `height=10` and `width=5`. Print the result.

Terminal
01
Tap code blocks below to assemble
Available Blocks