Python Basics
Theory: Named arguments
This lesson will be about parameters. We will learn what parameters exist, how they differ, and when to apply them.
What parameters are available
Arguments are the data passed to the function call. There are two types:
The first type is positional arguments. We pass them in the same order in which we define the function parameters:
The second type is named arguments. We pass them not as regular values but as a name=value pair. Therefore, we can write them in any order:
We can look carefully at the two examples above and notice that the two functions are identical.
Now we will discuss when we need to apply these types of arguments.
What parameters to use
The type of parameter you choose depends on who calls the function.
There are two reasons to use named arguments:
-
They increase readability because you can see the names at a glance
-
We do not need to specify all the intermediate parameters because they are unnecessary at the moment
The latter point is if the function has many optional parameters. Let us look at an example:
Named arguments can be passed at the same time as positional arguments. In that case, the positional ones should go at the beginning:
In this lesson, we have limited ourselves to basic knowledge to help you read sample code with named arguments.
Completed
0 / 43