Function as Default Parameter Python
Function as Default Parameter Python

What’s up, Guys? Today we will be learning the function as default parameter in python (also called python default parameter)

We should start….

Process of executing the function as default parameter

  • Create a function of default parameter
  • Call the function

Creating a function of default parameter

 def area(a=4, b=5):
    print(a,b)

Calling the function

area(1,9)
area(14, 500)
area()

Result:

1   9
14 500
4 5

Read Also: Geometry in Tkinter

Total Code for the function of default parameter in Python

#function as default parameter
def area(a=4, b=5):
    print(a,b)

area(1,9)
area(14, 500)
area() 

How does the function of default parameter work in Python?

Here….

def area(a=4, b=5):

def area(a=4, b=5): is a function we have defined. The name of the function is area and a=4, b=5 is the parameter.

print(a,b)

Now, what will print(a,b) do?

It will print the value of a and b, until it will be changed.

area(1,9)

Now, the value of a will be changed into 1 and b will be changed into 9.

And according to code in line 3, it’ll print 1 9.

area()

area() has no command to change the value, so it’ll print the default value 4 5.

We have learnt the whole process of the function of default parameter work in Python…

Amazed… Comment your confusion!!

Last modified: June 12, 2019

Author

Comments

Write a Reply or Comment

Your email address will not be published.