Function Argument And Parameter in Python

Function Argument And Parameter in Python

Parameter is the variable or constant or basically a information that is send to function in order to use inside the function body to perform any operations or to use in any way.

We used parameter inside the parenthesis of the function

Example:

def function_name(num):

  print(num)


function_name(43)

Some time we say same thing parameter and argument

But there is some different between parameter and argument

Diff: b/w Argument And Parameter

Some time we say same thing parameter and argument

But there is some different between parameter and argument


Example:

def function_name(world): # formal value or parameter, receiver

  print(world)

function_name(‘hi’)       #  actual value or argument, sender


Different Types Of Argument in Python

  • Keyword Argument
  • Default Argument
  • Required Argument

Keyword Argument in Python

Using keyword argument, we can change order of parameter as we mentioned in function declaration.

Example:

def show(name, num):

  print(name)

  print(num)

show(“Rushikesh”, 32)

# show(32, “Rushikesh”) # not correct

# show(num = 32, name = “Rushikesh”) # correct using keyword argument

Default Parameter / Argument in Python

To provide a default valve in function declaration, that parameter we say that  it is default one.

Example:

def show_name(f_name, l_name=“Jafri”): # default parameter

  print(f_name + l_name)

show_name(“Rushikesh”)  # did not provide value to default parameter

#show_name(“Rushikesh”,”Jethure”)  # override the default parameter

Required Argument in Python

When we set any parameter in function declaration, we have to use that order of position on the time of calling that function that is required.

Example:

def show_value(a, b, c):

  print(“a = ”+a)

  print(“b = ”+b)

  print(“c = ”+c)

show_value(3, 5, 1)


And when set any parameter to get value from user then some time we make parameter as default or optional and other required

Example:

def show_number(num1, num2 = 33):

  print(num1 + num2)

  # num1 is required and num2 is the optional

 

show_number(num2 = 43)

# override num2 but you will get an error, num1 is required


To view or add a comment, sign in

More articles by Rushikesh J.

  • Linux Operating System

    Linux Operating System ======================= => Linux is a community based OS => Linux is free & Open Source => Linux…

  • Infrastructure

    ================= Infrastructure ================= Servers (Machines) Databases Storage Network Security Backup =>…

  • Application Architectural Patterns

    =================================== 1) Monolithic Architecture (Outdated) 2) Microservices Architecture (Trending)…

  • DevOps Introduction

    =============== What is DevOps =============== DevOps = Development + Operations => DevOps is a culture/process in IT…

    2 Comments
  • Try and Exception in Python

    Exception is the error and is an event, which occur when program statements are executing. It disrupts the flow of…

  • Python Array With Examples

    Array in Python Array in Python Array is the collection of items having same data type with contiguous memory location.…

  • Python Date Object

    We can work with time and date with Python. There are two module in Python time and datetime that used to work with…

  • String Formatting WITH Problems and Solution

    What is String Formatting? It is the way to insert custom string or variable in a text (string). Using string…

  • SET Different Methods With Examples

    SET Method : add() Working: This method is used to add element to set. Syntax: set.

  • Python SET Comprehension With Examples

    What is Comprehension? •We create a sequence from a given sequence is called comprehension. •Sequence means list…

Insights from the community

Others also viewed

Explore topics