Open In App

Deep dive into Parameters and Arguments in Python

Last Updated : 24 Oct, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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




# Here a,b are the parameters
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)
    
# Here the values 1,2 are arguments
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)
    
# First name is Ram placed first
# Second name is Babu place second
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)
  
# Here we are explicitly assigning the values 
person_name(second_name="Babu",first_name="Ram")


Output:

RamBabu


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads