Functions in Python 3
Table of content
- Function
- Default value of argument
- Passing arbitrary arguments using *args
- Passing arbitrary keyword arguments using **kwargs
Function
Function is a block of code executed when it is called. The syntax for defining a function is as below.
def function_name(<arguments):
statement
return statement
Example of a simple function which takes no arguments.
Function which takes arguments and returns addition.
Function passing arguments with key.
Default value of argument
We can set default value for argument, if value is not passed for that argument it takes default value.
Passing arbitrary arguments using *args
If the number of argument function is not fixed we can use arbitrary argument
Passing arbitrary keyword arguments using **kwargs
We can pass arbitrary number of arguments with some values.
Thank you folks. If you like this Python 3 post, please do checkout my other post on Django with Python 3 series