In the previous lesson, you learned how to create and call Python functions using the def keyword. You also learned that functions become much more useful when they can work with different values instead of using fixed data.
Python allows you to pass information into functions using parameters and arguments. These concepts make functions flexible, reusable, and suitable for solving a wide variety of programming problems.
Although beginners often use the words parameter and argument interchangeably, they have different meanings. Understanding this difference is essential for writing clear and reusable Python functions.
In this lesson, you will learn what parameters and arguments are, how they work together, and how Python passes data from a function call to a function definition.
After completing this lesson, you will be able to:
A parameter is a variable defined in the function declaration. It acts as a placeholder that receives data when the function is called.
Parameters exist only inside the function and can be used like normal variables.
def function_name(parameter):
statements
def greet(name):
print("Hello", name)
In this example, name is the parameter because it is declared inside the function definition.
An argument is the actual value passed to a function when it is called.
The argument provides the data that is assigned to the corresponding parameter.
def greet(name):
print("Hello", name)
greet("Rahul")
Output
Hello Rahul
Here:
name is the parameter."Rahul" is the argument.| Parameter | Argument |
|---|---|
| Defined inside the function. | Passed when calling the function. |
| Acts as a placeholder. | Provides the actual value. |
| Exists only within the function. | Exists in the function call. |
| Receives data. | Sends data. |
Without parameters, functions would always perform the same operation using fixed values.
Parameters allow a single function to work with different inputs.
def add():
print(10 + 20)
add()
Output
30
This function always produces the same result.
def add(a, b):
print(a + b)
add(10, 20)
add(50, 70)
add(5, 8)
Output
30
120
13
The same function can now perform calculations using different values.
Most Python functions use positional parameters.
The order of parameters determines how arguments are assigned.
def student(name, age):
print("Name:", name)
print("Age:", age)
The function contains two positional parameters.
When calling the function, arguments are assigned according to their position.
def student(name, age):
print("Name:", name)
print("Age:", age)
student("Neha", 20)
Output
Name: Neha
Age: 20
The first argument is assigned to name, and the second argument is assigned to age.
Parameters can receive any Python data type.
def square(number):
print(number * number)
square(8)
Output
64
def welcome(name):
print("Welcome", name)
welcome("Amit")
Output
Welcome Amit
def display(items):
print(items)
display([10, 20, 30])
Output
[10, 20, 30]
Understanding how Python executes a function call is important.
Consider the following program.
def multiply(a, b):
print(a * b)
multiply(4, 5)
Execution Steps
multiply(4, 5).4 is assigned to parameter a.5 is assigned to parameter b.Output
20
Suppose you want to print student information.
def student(name, course):
print("Student:", name)
print("Course:", course)
student("Rahul", "Python")
student("Neha", "Data Analytics")
student("Amit", "Machine Learning")
Output
Student: Rahul
Course: Python
Student: Neha
Course: Data Analytics
Student: Amit
Course: Machine Learning
Notice that the same function is reused with different arguments.
Remember:
def add(a, b):
print(a + b)
add(10)
This produces a TypeError because one required argument is missing.
add(10, 20, 30)
This also results in a TypeError.
With positional arguments, the order of arguments must match the order of parameters.
Choose meaningful names such as student_name, marks, or radius instead of generic names like x or y whenever possible.
In this section, you learned the difference between Python function parameters and arguments and how they work together to make functions reusable. You explored positional parameters, positional arguments, passing different data types, and followed the execution flow of a function call step by step. You also reviewed common beginner mistakes related to function calls. In the next section, you will explore different types of function arguments, including keyword arguments, default arguments, variable-length arguments using *args and **kwargs, positional-only parameters, keyword-only parameters, and argument packing and unpacking.
In the previous section, you learned the difference between parameters and arguments and how values are passed into functions. Python provides several ways to pass arguments to functions, allowing you to create flexible and reusable code.
In this section, you will explore different types of function arguments, including positional arguments, keyword arguments, default arguments, variable-length arguments, positional-only parameters, keyword-only parameters, and argument packing and unpacking.
Python supports several types of arguments that make functions more flexible.
*args)**kwargs)Positional arguments are assigned to function parameters based on their position.
def student(name, age):
print("Name:", name)
print("Age:", age)
student("Rahul", 20)
Output
Name: Rahul
Age: 20
The first argument is assigned to name, while the second argument is assigned to age.
Keyword arguments allow you to specify the parameter names while calling the function.
def student(name, age):
print("Name:", name)
print("Age:", age)
student(age=20, name="Rahul")
Output
Name: Rahul
Age: 20
The order of keyword arguments does not matter because each value is assigned using its parameter name.
Python allows positional and keyword arguments to be used together, but positional arguments must always appear before keyword arguments.
def employee(name, salary):
print(name, salary)
employee("Amit", salary=50000)
employee(name="Amit", 50000)
This results in a SyntaxError because positional arguments cannot follow keyword arguments.
Default arguments provide predefined values for parameters. If the caller does not supply a value, the default value is used.
def greet(name="Guest"):
print("Welcome", name)
greet()
greet("Neha")
Output
Welcome Guest
Welcome Neha
Default arguments reduce the need to pass values for every function call.
*args)Sometimes the number of arguments is not known in advance. Python provides *args to collect multiple positional arguments into a tuple.
def total(*numbers):
print(sum(numbers))
total(10, 20)
total(5, 10, 15, 20)
Output
30
50
The variable numbers is treated as a tuple containing all positional arguments.
**kwargs)The **kwargs syntax collects multiple keyword arguments into a dictionary.
def student(**details):
for key, value in details.items():
print(key, ":", value)
student(name="Rahul", age=20, city="Delhi")
Output
name : Rahul
age : 20
city : Delhi
This is useful when different function calls may provide different sets of keyword arguments.
Python 3.8 introduced positional-only parameters using the forward slash (/).
Parameters placed before / can only receive positional arguments.
def function_name(parameter1, parameter2, /):
statements
def divide(a, b, /):
print(a / b)
divide(20, 5)
Output
4.0
The following call is invalid:
divide(a=20, b=5)
It raises a TypeError because a and b are positional-only parameters.
Python also supports keyword-only parameters using the asterisk (*).
Parameters after * must be passed using keyword arguments.
def function_name(*, parameter):
statements
def student(*, name, age):
print(name, age)
student(name="Rahul", age=20)
Output
Rahul 20
The following call is invalid:
student("Rahul", 20)
It raises a TypeError because the parameters are keyword-only.
Argument packing collects multiple values into a single parameter.
*argsdef numbers(*values):
print(values)
numbers(10, 20, 30, 40)
Output
(10, 20, 30, 40)
Argument unpacking sends elements of a collection as individual arguments.
def add(a, b, c):
print(a + b + c)
values = [10, 20, 30]
add(*values)
Output
60
def student(name, age):
print(name, age)
data = {
"name": "Neha",
"age": 22
}
student(**data)
Output
Neha 22
Consider the following function.
def addition(a, b):
return a + b
result = addition(25, 15)
print(result)
Execution Steps
addition() is defined.25 and 15.a and b.result.Output
40
Always place positional arguments before keyword arguments.
Default arguments should be defined after required parameters.
*args and **kwargsUse *args for multiple positional arguments and **kwargs for multiple keyword arguments.
Use * to unpack lists or tuples and ** to unpack dictionaries.
Parameters before / must always receive positional arguments.
In this section, you learned about the different types of Python function arguments, including positional arguments, keyword arguments, default arguments, variable-length arguments using *args and **kwargs, positional-only parameters, keyword-only parameters, and argument packing and unpacking. You also explored the execution flow of function calls and reviewed common beginner mistakes. In the next section, you will apply these concepts through practical examples such as student information systems, salary calculators, shopping bill generators, area calculators, temperature converters, flexible calculators using *args, and user profile functions using **kwargs.
Understanding different types of parameters and arguments becomes much easier when you apply them in real programs. Functions allow you to reuse code, simplify complex tasks, and make programs easier to maintain.
In this section, you will build practical examples using positional arguments, keyword arguments, default arguments, *args, **kwargs, and argument unpacking. These examples demonstrate how flexible Python functions can be in real-world applications.
This function accepts a student’s name, age, and course, then displays the information.
def student(name, age, course):
print("Name :", name)
print("Age :", age)
print("Course :", course)
student("Rahul", 20, "Python")
Output
Name : Rahul
Age : 20
Course : Python
The function can be reused for any student by passing different arguments.
This function calculates an employee’s annual salary.
def annual_salary(monthly_salary):
return monthly_salary * 12
salary = annual_salary(45000)
print("Annual Salary =", salary)
Output
Annual Salary = 540000
This function accepts multiple item prices and calculates the total bill using *args.
def total_bill(*prices):
return sum(prices)
print(total_bill(250, 180, 120, 450))
Output
1000
The function accepts any number of prices.
This function calculates the area of a rectangle.
def rectangle_area(length, width):
return length * width
print(rectangle_area(12, 8))
Output
96
This function converts Fahrenheit to Celsius.
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
print(fahrenheit_to_celsius(98.6))
Output
37.0
*argsThis function adds any number of values.
def addition(*numbers):
total = 0
for number in numbers:
total += number
return total
print(addition(5, 10))
print(addition(5, 10, 15, 20))
Output
15
50
The function works regardless of how many numbers are supplied.
**kwargsThis function accepts any number of keyword arguments and displays them.
def profile(**details):
for key, value in details.items():
print(key, ":", value)
profile(
name="Neha",
age=22,
city="Delhi",
profession="Teacher"
)
Output
name : Neha
age : 22
city : Delhi
profession : Teacher
The elements of a list can be unpacked into function arguments.
def multiply(a, b, c):
return a * b * c
numbers = [2, 3, 4]
print(multiply(*numbers))
Output
24
The * operator unpacks the list into separate arguments.
Dictionaries can be unpacked using the ** operator.
def employee(name, department):
print(name)
print(department)
data = {
"name": "Amit",
"department": "Sales"
}
employee(**data)
Output
Amit
Sales
Default values make function calls shorter when common values are used.
def welcome(name="Guest"):
print("Welcome", name)
welcome()
welcome("Rahul")
Output
Welcome Guest
Welcome Rahul
Consider the following program.
def calculate_total(price, quantity):
return price * quantity
total = calculate_total(250, 4)
print(total)
Execution Steps
calculate_total() is defined.250 and 4.price and quantity.total.Output
1000
Use names like student_name, monthly_salary, or temperature instead of generic names such as x or y.
Each function should perform one well-defined task.
Provide default values only when they make sense for most function calls.
*args and **kwargs Only When NeededThey provide flexibility but should not replace clearly defined parameters unnecessarily.
Returning values makes functions more reusable because the caller decides how to use the result.
*args when a fixed number of parameters is sufficient.return statement would be more appropriate.In this section, you applied Python function parameters and arguments to practical programming examples such as student information systems, salary calculations, shopping bill generation, area calculations, temperature conversion, flexible calculators using *args, user profiles using **kwargs, and argument unpacking with lists and dictionaries. You also learned best practices for designing reusable functions and reviewed common beginner mistakes. In the final section, you will review the complete lesson through a summary, key takeaways, frequently asked questions, coding exercises, interview questions, a mini project, and a preview of the next lesson on Python Return Statement & Variable Scope.
In this lesson, you learned how Python functions accept data through parameters and arguments, making functions flexible and reusable. You explored the difference between parameters and arguments, learned how Python assigns values during a function call, and understood why parameters are essential for writing reusable code.
You studied different types of function arguments, including positional arguments, keyword arguments, default arguments, variable-length arguments using *args, keyword variable-length arguments using **kwargs, positional-only parameters, keyword-only parameters, and argument packing and unpacking. These features allow Python functions to handle simple as well as complex input requirements.
Through practical examples such as student information systems, employee salary calculators, shopping bill generators, area calculators, temperature converters, flexible calculators, and user profile functions, you learned how parameters and arguments are used in real-world Python programs.
Mastering parameters and arguments is an important step toward writing professional, modular, and reusable Python applications.
*args collects multiple positional arguments into a tuple.**kwargs collects multiple keyword arguments into a dictionary.*, while dictionaries can be unpacked using **.A parameter is a variable declared in a function definition that receives data when the function is called.
An argument is the actual value supplied to a function during a function call.
Parameters are placeholders in the function definition, while arguments are the actual values passed to those parameters.
Positional arguments are assigned to parameters according to their order in the function call.
Keyword arguments specify the parameter name explicitly when calling a function.
*args?*args allows a function to accept any number of positional arguments.
**kwargs?**kwargs allows a function to accept any number of keyword arguments.
Argument unpacking uses * to unpack lists or tuples and ** to unpack dictionaries when calling a function.
*args.**kwargs.*args?**kwargs?Create a Python program that uses different types of function parameters and arguments to manage employee information.
Your program should:
employee_info(name, department, salary) that displays employee details.calculate_bonus(salary, percentage=10) that calculates the bonus using a default argument.total_salary(*amounts) that calculates the total salary using *args.employee_profile(**details) that displays employee details using **kwargs.Employee Name : Rahul
Department : Sales
Salary : 50000
Bonus : 5000
Total Salary : 150000
Employee Profile
Name : Rahul
Age : 28
City : Delhi
Designation : Manager
Congratulations! You have mastered Python function parameters and arguments. You now understand how to pass data into functions using positional arguments, keyword arguments, default arguments, *args, **kwargs, and argument unpacking. These concepts will help you design flexible and reusable functions for a wide range of applications.
In the next lesson, you will learn Python Return Statement & Variable Scope: Complete Guide for Beginners. You will explore how the return statement sends values back to the caller, understand local and global variables, learn variable scope rules, and discover best practices for writing clean and maintainable Python functions.