Andromeda
Note

Arguments (Python)

Definition

Arguments are the real data values provided and passed into a function when it is called.

Why It Matters

Arguments bring functions to life by giving them concrete data to operate on. They allow a single generalized function to solve a multitude of specific problems, separating the logic from the actual data.

Core Concepts

  • Pass: The act of sending a value into the function during a call.
  • Positional Arguments: Arguments matched to parameters based purely on the order they are provided in the function call.
  • Keyword Arguments: Arguments explicitly linked to parameter names (e.g., greet(name='Alice')), which makes the call order-independent and self-documenting.
  • Arbitrary Arguments: Passing a variable number of arguments using *args or **kwargs.
def greet(name, greeting="Hello"):
    print(f"{greeting}, {name}!")

# Positional arguments
greet("Alice", "Hi")

# Keyword arguments
greet(greeting="Welcome", name="Bob")

Connected Concepts