Skip to content
Related Articles

Related Articles

Improve Article

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. 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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



My Personal Notes arrow_drop_up
Recommended Articles
Page :