Python for Data Analytics • Lesson 17
Function Arguments & Scope
Learn how Python functions receive information — positional arguments, keyword arguments, default values, *args and **kwargs — and how variable scope decides where a name exists.
0 of 8 concepts completed
Complete the activity and related MCQ to unlock the next concept.
Positional Arguments
When arguments are passed by position, Python matches them to parameters in the order they were defined. First argument → first parameter, second → second, and so on.
Learn by Seeing
Match by order
def introduce(name, age):
print(name, age)
introduce("Rahul", 22)
# Rahul 22"Rahul" lands on name, 22 lands on age — purely by position.
Interactive Activity
In introduce("Rahul", 22), which value goes to name?
Hint: The first argument is matched to the first parameter.
Python Analyst Mindset
Arguments are how a function talks to the world
A good analyst function takes exactly the inputs it needs, returns exactly what the caller asked for, and keeps its internal names to itself. Arguments and scope are what make that contract clean.
Pass
Positional or keyword.
Default
Fall back when omitted.
Flexible
*args and **kwargs.
Scope
Locals stay local.
Mini-Project
Sales Bonus Calculator
Build a small function that takes an employee's name and monthly sales, applies a default commission rate of 5%, and returns a formatted summary. Then call it for three different employees.
def bonus_summary(name, sales, rate=0.05):
bonus = sales * rate
return f"{name} earned a bonus of {bonus:.2f}"
print(bonus_summary("Alice", 80000)) # 4000.00
print(bonus_summary("Bob", 120000, rate=0.08)) # 9600.00
print(bonus_summary(sales=50000, name="Carol")) # 2500.00This exercise combines positional arguments, keyword arguments, defaults, and scope — the full toolkit from this lesson.
Lesson Summary
What you learned
Matched by order.
Bound by parameter name.
Used when the caller omits the argument.
Collects extra positional arguments into a tuple.
Collects extra keyword arguments into a dictionary.
Locals stay inside the function; globals are readable everywhere.
Frequently Asked Questions