Creating A Function in Python
Creating A Function in Python
We can create a user-defined function in Python, using the def keyword. We can add
any type of functionalities and properties to it as we require.
2222222222222
return num3
# Driver code
num1, num2 = 5, 15
ans = add(num1, num2)
print(f"The addition of {num1} and {num2} results {ans}.")
3333333333
Python Function Arguments
Arguments are the values passed inside the parenthesis of the function. A function
can have any number of arguments separated by a comma.
In this example, we will create a simple function in Python to check whether the
number passed as an argument to the function is even or odd.
Default argument
Keyword arguments (named arguments)
Positional arguments
Arbitrary arguments (variable-length arguments *args and **kwargs)
Let’s discuss each type in detail.
Default Arguments
A default argument is a parameter that assumes a default value if a value is not
provided in the function call for that argument. The following example illustrates
Default arguments.