Default Arguments in Python Functions

python_tutorials

Functions in Python are used to implement logic that you want to execute repeatedly at different places in your code. You can pass data to these functions via function arguments. In addition to passing arguments to functions via a function call, you can also set default argument values in Python functions. These default values are assigned to function arguments if you do not explicitly pass a parameter value to the given argument. Parameters are the values actually passed to function arguments.

In this article, you will see how to use default arguments in Python functions. But first, we will see how to define a function in Python and how to explicitly pass values to function arguments.

Function without Arguments

Let’s define a very simple Python function without any arguments:

def my_function():
    print("This is a function without arguments")

The above script defines a function, my_function, which doesn’t accept any arguments and simply prints a string.

The following script shows how you’d actually call the my_function() function:

my_function()

In the output, you should see a simple statement printed to the screen by the my_function() function:

This is a function without arguments

Function with

To finish reading, please visit source site