Python Essentials for AI Engineer

Course Content

Python Essentials for AI Engineer

6 sections · 48 lessons

What is the difference between parameters and arguments?


What you need to know

The two sides of a call

Python
def greet(name, greeting="Hi"):      # name, greeting -> PARAMETERS    return f"{greeting} {name}"print(greet("Asha"))                 # Hi Asha      -> "Asha" is an ARGUMENTprint(greet("Ravi", "Namaste"))      # Namaste Ravi -> positional argumentsprint(greet(greeting="Hello", name="Meera"))   # Hello Meera -> keyword arguments

A handy memory aid: Parameter = Placeholder, Argument = Actual value.

How binding works

When you call a function, Python matches arguments to parameters: positional arguments first, left to right, then keyword arguments by name. Then it fills any unmatched parameters from their defaults. If something does not fit, you get a TypeError before the body runs:

Python
def g(a, b): return a + btry:    g(1, a=2)except TypeError as e:    print(e)        # g() got multiple values for argument 'a'

Keyword-only and positional-only parameters

A bare * in the definition means "every parameter after this must be passed by keyword". A / means "every parameter before this must be passed by position" (Python 3.8+).

Python
def f(x, /, y, *, z):    return x + y + zprint(f(1, 2, z=3))          # 6print(f(1, y=2, z=3))        # 6# f(x=1, y=2, z=3)  -> TypeError: x is positional-only# f(1, 2, 3)        -> TypeError: z is keyword-only

Keyword-only parameters make call sites self-documenting. Positional-only parameters let a library rename a parameter later without breaking callers; many built-ins use them, which is why len(obj=[1]) fails.

A real-life example

A team wraps their LLM call in a helper:

Python
def call_llm(prompt, model, temperature, max_tokens):    return f"{model} temp={temperature} max_tokens={max_tokens}"# Someone swaps two numbers. No error — both are just numbers.print(call_llm("Summarise this", "chat-small", 512, 0.2))# chat-small temp=512 max_tokens=0.2

The provider rejects the request, or worse, a local model clamps the values and produces garbage for a week. The fix is to make the settings keyword-only:

Python
def call_llm(prompt, *, model, temperature=0.2, max_tokens=512):    return f"{model} temp={temperature} max_tokens={max_tokens}"print(call_llm("Summarise this", model="chat-small", max_tokens=300))# chat-small temp=0.2 max_tokens=300

Now call_llm("x", "chat-small", 512, 0.2) fails immediately with a TypeError, and every call site reads clearly. The major LLM SDKs use keyword-only arguments for exactly this reason.

Follow-up questions to expect

  • "What happens if you pass too many arguments?" — A TypeError like f() takes 1 positional argument but 2 were given.
  • "Can positional arguments come after keyword arguments in a call?" — No, f(a=1, 2) is a SyntaxError. Positional arguments come first.
  • "What are *args and **kwargs in this picture?" — Parameters that collect any extra positional or keyword arguments. They are covered in their own question.