Lesson 03
Python Parameters and Arguments — All 5 Types with Examples
Learn Python positional, default, keyword, *args, and **kwargs with diagrams, mapping tables, FastAPI-style patterns, playground, and quiz.
What you will learn
- The difference between parameters and arguments
- Positional, default, and keyword arguments
- Variable-length
*args - Keyword variable-length
**kwargs - Combining all five in one function (orders, student reports)
The big picture
Learn all 5 argument types used in professional Python — from basic positional arguments to *args and **kwargs used in frameworks like FastAPI and Django.
Before the five types, see how data travels.
Key idea: Arguments are the actual values sent by the caller. Parameters are the variables that receive those values inside the function.
This continues from Function Approaches.
Parameters vs arguments
This distinction appears in almost every Python interview.
| Parameters | Arguments | |
|---|---|---|
| Where | Function heading | Function call |
| What | Placeholders waiting for values | Real values passed in |
| Example | def add(a, b) |
add(10, 20) |
def add(a, b): # a, b → parameters (placeholders)
return a + b
add(10, 20) # 10, 20 → arguments (actual values)Memory rule: Parameter = placeholder → Argument = actual value
Formal vs local (from the teaching notes):
def sumop(a, b): # a, b → formal parameters
c = a + b # c → local variable
return cThe 5 types of arguments
These five categories form Python’s complete argument-passing mechanism.
Type 1 — Positional arguments
Most common. Python matches values from left to right. Count must equal the number of required parameters.
def show_student(sno, sname, marks):
print(sno, sname, marks)
show_student(101, "Alice", 92.5)
show_student(102, "Bob", 85.0)| Position | Value | Parameter |
|---|---|---|
| 1 | 101 |
sno |
| 2 | "Alice" |
sname |
| 3 | 92.5 |
marks |
Rules: number of arguments must equal number of required parameters. Order cannot change.
Type 2 — Default arguments
A parameter already has a value. Use it when a family of calls shares a common value (for example crs="PYTHON").
def enroll(name, course="Python"):
print(name, course)
enroll("Bob") # Python (default)
enroll("Bob", "Django") # Django (override)Multiple defaults (from the teaching files):
def insert_student(sno, sname, marks, crs="PYTHON", country="INDIA"):
print(sno, sname, marks, crs, country)
insert_student(100, "RS", 3.5)
insert_student(500, "DR", 1.5, country="USA", crs="HTML")Rule: default parameters come after positional parameters.
def f(a, b=10): # correct
pass
# def f(a=10, b): # SyntaxError: parameter without a default follows parameter with a defaultType 3 — Keyword arguments
Use the parameter name. Order no longer matters.
def display(a, b, c):
print(a, b, c)
display(10, 20, 30) # positional
display(c=30, a=10, b=20) # keyword — any order
display(10, 20, c=30) # mix: positional first, then keywordUse when you know names but not order, or for optional settings and readability.
Rule: positional arguments must come before keyword arguments.
display(10, 20, c=30) # correct
# display(c=30, 10, 20) # SyntaxError: positional argument follows keyword argument
# display(a=10, b1=20, c=30) # TypeError: unexpected keyword argument 'b1'Type 4 — Variable length (*args)
Without *args you need a new definition for every argument count. With *args, one definition stores extra values in a tuple.
def total(*nums): # *nums type is tuple
print(nums, type(nums), len(nums))
print("sum =", sum(nums))
total(10, 20) # (10, 20) sum = 30
total(1, 2, 3, 4, 5) # (1, 2, 3, 4, 5) sum = 15
total() # () sum = 0Practical example from the teaching files:
def find_total(sno, sname, *vals, city="HYD"):
print(sno, sname, city, vals, "sum =", sum(vals))
find_total(100, "KV", 10, 20, 30, 40, 50)
find_total(500, "RS")
find_total(700, "MC", -1, -2, city="AUS")Key fact: *args is always a tuple. Only one *args per function.
Type 5 — Keyword variable length (**kwargs)
Unknown named fields (user profiles, optional API keys) pack into a dict.
def profile(**info):
print(info, type(info))
for k, v in info.items():
print(k, "-->", v)
profile(name="Alice", city="Hyderabad", skill="Python")
profile() # {}Student marks by subject (teaching example):
def find_total_marks(sno, sname, cls, city="HYD", **subject_marks):
print(sno, sname, cls, city)
print(subject_marks)
print("TOTAL =", sum(subject_marks.values()))
find_total_marks(10, "Rajesh", "X", Tel=60, Eng=70, Maths=89)
find_total_marks(40, "RS", "Research")Key fact: **kwargs is always a dict. Only one **kwargs, and it is last in the heading.
*args vs **kwargs
| Feature | *args |
**kwargs |
|---|---|---|
| Accepts | Extra positional | Extra keyword |
| Type | tuple |
dict |
| Example | (1, 2, 3) |
{"name": "Raj"} |
| Use | Unlimited values | Unlimited named values |
Ultimate heading — all five together
From the teaching notes, write parameters in this definition order:
def func(a, b, *values, city="HYD", **details):
print("a =", a)
print("b =", b)
print("values =", values)
print("city =", city)
print("details =", details)
func(10, 20, 30, 40, city="AP", age=25)Heading order (mandatory): positional → *args → default / keyword-only → **kwargs.
Call order: leftover positionals fill *args; leftover keywords fill **kwargs. Never put a positional after a keyword in the call.
Real-world — e-commerce order
Positional + default + **kwargs — the same pattern as APIs where optional fields vary.
def create_order(customer, product, quantity=1, **extra):
print("customer:", customer)
print("product:", product)
print("quantity:", quantity)
print("extra:", extra)
create_order("Mahesh", "Laptop", warranty="2 Years", color="Black")| Parameter | Value |
|---|---|
customer |
"Mahesh" |
product |
"Laptop" |
quantity |
1 (default) |
extra |
{"warranty": "2 Years", "color": "Black"} |
Mini project — student report (all five)
def student_report(sno, name, *marks, city="HYD", **subjects):
print("name:", name)
print("city:", city)
print("marks tuple:", marks)
print("total:", sum(marks))
print("subjects:", subjects)
student_report(101, "Alice", 80, 90, 70, city="Mumbai", Maths=80, English=90)Common mistakes
| Mistake | Error |
|---|---|
add(10) when def add(a, b) |
TypeError — missing argument |
def f(a=1, b) |
SyntaxError — default before required |
f(c=30, 10) |
SyntaxError — positional after keyword |
def f(*a, *b) |
SyntaxError — only one *args |
def f(**a, **b) |
SyntaxError — only one **kwargs |
Interview cheat sheet
| Question | Answer |
|---|---|
| Parameter vs argument | Placeholder vs actual value |
| Default arguments | Predefined value; last in heading |
| Keyword arguments | Order does not matter |
*args type |
tuple |
**kwargs type |
dict |
Multiple *args / **kwargs? |
No |
| Call priority | Positional before keyword |
Next: Local and Global Variables.
Loading playground…
Check your understanding
Parameters and arguments quiz
What is the memory rule for parameter vs argument?
1 / 10