Default Arguments in Python Functions

Default Arguments in Python Functions

If value of a parameter is already known then you can assign default values to a Python function’s parameter. Further, the default values can be specified in the function header.
For example,

def sum(x, y, z=15):
s=x+y+z
return s
In the above program, value of parameter z is 15.
If in program, function call sum(20, 30) appears i.e the third argument is missing.
Actually, function call sum(20, 30, 15) will be used and no argument is missing.

See the below  program and output it output

Default Arguments in Python Functions

 

Leave a Comment

Your email address will not be published. Required fields are marked *

©Postnetwork-All rights reserved.