Arguments and Parameters in Python | CBSE Class 12
Introduction
When we need our python code to allow code reusability and modular programming, we prefer to use functions in our program because the functions make our code more flexible and dynamic with the usage of arguments and parameters in python to pass information into them.
In this tutorial we are going to Understand the difference between arguments and parameters, and also discussing how to use various types of arguments,
Let’s get start
Arguments in Python
Arguments are the actual values passed to a function when it is called. They are the data that the function will work with.
The moment when the values of x and y are passed to the function call for execution the values lets ‘Qissba’ and ‘Kabeer’ are called arguments. like :
greet(“Qissba“, “Kabeer“) # “Qissba” and “Kabeer” are arguments
Note that the value of x and y might be different for given by different users and depends on the imagination that’s why we call these values as arguments (read the concept of imaginary values).
Parameters in Python
Parameters are the variables listed inside the parentheses in the function definition. They act as placeholders for the values that the function will receive when it is called.
The moment when variable X and Y receive the values for giving at the time of execution x and y are defined in the function header and the exact values are not given to be used then these variables x and y are called parameters like :
def greet( name, greeting): # ‘ name’ and ‘greeting’ are parameters
print(greeting, name)
Note that x and y are formally written in function header that indicates that two actual values will come here at the time of execution and these values may be different according the users requirement.
As we have seen that we use values to be passed in a function and for this we define variables to receive these values in function definition and these values are sent via a function call statement.
for example
def calcsum(x, y):
s = x + y
return s
num1= float(input("Enter first number"))
num2= float(input("Enter second number"))
sum = calcsum (num1,num2)
print("the sum of given numbers is " sum)
Here you see that above program has a function named calcsum that receives two values and when this function is is being called or invoked, the values received by the function are passed to the function body to get the required output according to the functionality of our defined function. Now there are two positions where values and variables play an important role
Number One is, when values are received by variables x and y in function definition.
Number Two, is when these values are passed to the function called for execution.
here comes the concept where you can understand the difference between arguments and parameters in ython.
Important -: If you have any confusion between arguments and parameters in python then you can use the only one term argument for both as
- formal arguments
- actual arguments
Also can use the only term parameter for both as
- formal parameters and
- actual parameters
Difference between Arguments and Parameters
In Python, arguments and parameters are closely related but distinct concepts when discussing functions:
From the above discussion, we may have some of the key differences in light of the Scope, Purpose and Usage like :
-
Scope: Parameters exist only within the function definition. Arguments exist in the scope where the function is called.
-
Purpose: Parameters define the expected input for a function. Arguments provide the actual values for the function to execute.
-
Usage: Parameters are specified in the function definition. Arguments are passed when calling the function.
Exam Time
Chapter : Using Python Modules
IMPORTANT QUESTIONS : Asked in examinations of CBSE Class 12th Computer Science