...

/

Arguments

Arguments

Learn about the usage of different types of arguments in functions.

Types of arguments

Arguments in a Python function can be of four types:

  • Positional arguments
  • Keyword arguments
  • Variable-length positional arguments
  • Variable-length keyword arguments

Positional and keyword arguments are often called required arguments, whereas variable-length arguments are called optional arguments.

Positional arguments

Positional arguments must be passed in the correct positional order. For example, if a function expects an int, float, and str to be passed to it, then while calling this function, the arguments must be passed in the same order.

Python 3.8
def fun(i, j, k) :
print(i + j)
print(k.upper( ))
fun(10, 3.14, 'Rigmarole') # correct call
fun('Rigmarole', 3.14, 10) # error, incorrect order

When passing positional arguments, the number of arguments ...