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.

Your progress0%

0 of 8 concepts completed

Complete the activity and related MCQ to unlock the next concept.

Concept 1POSITIONAL

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.

01

Pass

Positional or keyword.

02

Default

Fall back when omitted.

03

Flexible

*args and **kwargs.

04

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.00

This exercise combines positional arguments, keyword arguments, defaults, and scope — the full toolkit from this lesson.

Lesson Summary

What you learned

Positional arguments

Matched by order.

Keyword arguments

Bound by parameter name.

Default arguments

Used when the caller omits the argument.

*args

Collects extra positional arguments into a tuple.

**kwargs

Collects extra keyword arguments into a dictionary.

Scope

Locals stay inside the function; globals are readable everywhere.

Frequently Asked Questions

Common questions about arguments & scope