A function can have more than one argument.
Keyword Arguments
Passing values by their names.
Code
PYTHON
Input
Output
Possible Mistakes - Keyword Arguments
Code
PYTHON
Input
Output
Positional Arguments
Values can be passed without using argument names.
- These values get assigned according to their position.
- Order of the arguments matters here.
Code
PYTHON
Input
Output
Possible Mistakes - Positional Arguments
Mistake - 1
Code
PYTHON
Input
Output
Mistake - 2
Code
PYTHON
Input
Output
Default Values
Example - 1
Code
PYTHON
Input
Output
Example - 2
Code
PYTHON
Input
Output
Example - 3
Code
PYTHON
Input
Output
Example - 4
Code
PYTHON
Input
Output
Example - 5
Code
PYTHON
Input
Output
Non-default arguments cannot follow default arguments.
Example - 6
Code
PYTHON
Input
Output
Passing Immutable Objects
Code
PYTHON
Input
Output
Even though variable names are same, they are referring to two different objects. Changing the value of the variable inside the function will not affect the variable outside.