Default arguments in Python

A default argument is an argument that assumes a default value if a value is not provided in the function call for that argument. The following example gives an idea on default arguments, it prints default age if it is not passed −


 Live Demo

# Function definition is here
def printinfo( name, age = 35 ):
"This prints a passed info into this function"
print "Name: ", name
print "Age ", age
# Now you can call printinfo function
printinfo( age=50, name="miki" )
printinfo( name="miki" )


When the above code is executed, it produces the following result −

Name: miki
Age 50
Name: miki
Age 35