Many electronics come with default settings, the ones that most people use. But it also gives the user the opportunity to change these settings for extra customization. Python offers a similar feature with default parameters. These parameters will take on their default value unless they are filled. This means you can call the function only giving the mandatory arguments, but you have the opportunity to further customize the function by giving new values to default parameters.
To turn a parameter into a default parameter, give it a value in the header.
def greet(your_name, other_name = "friend"):
print("Hello, " + other_name + ", I'm " + your_name + "!")
Now, if we call greet("Mr. McClung")
It will print "Hello, friend, I'm Mr. McClung!" The parameter other_name took on the default value "friend".
Now, if we call greet("Mr. McClung", "Joe") or greet("Mr. McClung", other_name = "Joe")
It will print "Hello, Joe, I'm Mr. McClung!" because the parameter other_name has taken on the value "Joe."
You may use any number of default parameters, but these default parameters must come after all mandatory parameters. (Otherwise, you would not be able to use positional arguments.)
def fun(first, second, third = 3, fourth = 4):
def fun(first, second = 2, third, fourth = 4): The default parameter, second, can't come before the standard argument third.