Default argument

Default Argument


In Python the default argument is an argument that takes a default value if no value is provided in the function call. The following example uses default arguments, that prints default salary when no argument is passed.

Example:

def printinfo( name, salary = 3500):
print (“Name: “, name)
print (“Salary: “, salary)
return
printinfo(“Mani”)

Output:

Name: Mani

Salary: 3500

When the above code is changed as print info(“Ram”,2000) it produces the following output:

Output:

Name: Ram

Salary: 2000

In the above code, the value 2000 is passed to the argument salary, the default value already assigned for salary is simply ignored.

Python : Default argument Program List