Page 518 - ComputerScience_Class_11
P. 518
UNDERSTANDING PARAMETERS AND ARGUMENTS
In Python, functions can accept arguments and parameters, which are key to passing data between functions. These
concepts allow you to pass information to a function, enabling it to perform tasks based on dynamic input.
Parameters
Parameters are the variables listed inside the parentheses in the function definition. They act as placeholders for the
values that will be passed into the function when it is called. When you define a function, you specify parameters to
define what kind of input the function will accept.
Syntax of parameters:
def function_name(parameter1, parameter2):
#statements
Where:
• parameter1, parameter2, etc. are the parameters of the function.
• These parameters will hold the values passed when the function is called.
Arguments
Arguments are the actual values you pass to a function when you call it. The values you pass are assigned to the
function's parameters. These values are used by the function to perform its task.
Syntax of arguments:
function_name(argument1, argument2)
Where:
• argument1, argument2, etc. are the actual values you pass to the function.
Program 3: Write a program to calculate the area of a rectangle.
Program 3.py
File Edit Format Run Options Window Help
def calculate_area(length, width):
area = length * width
print("The area of the rectangle is:", area)
length = int(input("Enter the length of the rectangle: "))
width = int(input("Enter the width of the rectangle: "))
calculate_area(length, width)
Output
Enter the length of the rectangle: 5
Enter the width of the rectangle: 3
The area of the rectangle is: 15
516 Touchpad Computer Science (Ver. 3.0)-XI

