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
1def greet(name, greeting="Hi"): # name, greeting -> PARAMETERS2 return f"{greeting} {name}"34print(greet("Asha")) # Hi Asha -> "Asha" is an ARGUMENT5print(greet("Ravi", "Namaste")) # Namaste Ravi -> positional arguments6print(greet(greeting="Hello", name="Meera")) # Hello Meera -> keyword argumentsA 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:
1def g(a, b): return a + b2try:3 g(1, a=2)4except TypeError as e:5 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+).
1def f(x, /, y, *, z):2 return x + y + z34print(f(1, 2, z=3)) # 65print(f(1, y=2, z=3)) # 66# f(x=1, y=2, z=3) -> TypeError: x is positional-only7# f(1, 2, 3) -> TypeError: z is keyword-onlyKeyword-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:
1def call_llm(prompt, model, temperature, max_tokens):2 return f"{model} temp={temperature} max_tokens={max_tokens}"34# Someone swaps two numbers. No error — both are just numbers.5print(call_llm("Summarise this", "chat-small", 512, 0.2))6# chat-small temp=512 max_tokens=0.2The 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:
1def call_llm(prompt, *, model, temperature=0.2, max_tokens=512):2 return f"{model} temp={temperature} max_tokens={max_tokens}"34print(call_llm("Summarise this", model="chat-small", max_tokens=300))5# chat-small temp=0.2 max_tokens=300Now 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
TypeErrorlikef() takes 1 positional argument but 2 were given. - "Can positional arguments come after keyword arguments in a call?" — No,
f(a=1, 2)is aSyntaxError. Positional arguments come first. - "What are
*argsand**kwargsin this picture?" — Parameters that collect any extra positional or keyword arguments. They are covered in their own question.