Deep dive into Parameters and Arguments in Python
Last Updated :
24 Oct, 2020
There is always a little confusion among budding developers between a parameter and an argument, this article focuses to clarify the difference between them and help you to use them effectively.
Parameters:
A parameter is the variable defined within the parentheses during function definition. Simply they are written when we declare a function.
Example:
Python3
def sum (a,b):
print (a + b)
sum ( 1 , 2 )
|
Output:
3
Arguments:
An argument is a value that is passed to a function when it is called. It might be a variable, value or object passed to a function or method as input. They are written when we are calling the function.
Example:
Python3
def sum (a,b):
print (a + b)
sum ( 1 , 2 )
|
Output:
3
Types of arguments in python:
Python functions can contain two types of arguments:
- Positional Arguments
- Keyword Arguments
Positional Arguments:
Positional Arguments are needed to be included in proper order i.e the first argument is always listed first when the function is called, second argument needs to be called second and so on.
Example:
Python3
def person_name(first_name,second_name):
print (first_name + second_name)
person_name( "Ram" , "Babu" )
|
Output:
RamBabu
Keyword Arguments:
Keyword Arguments is an argument passed to a function or method which is preceded by a keyword and an equal to sign. The order of keyword argument with respect to another keyword argument does not matter because the values are being explicitly assigned.
Python3
def person_name(first_name,second_name):
print (first_name + second_name)
person_name(second_name = "Babu" ,first_name = "Ram" )
|
Output:
RamBabu
Please Login to comment...