I started writing about "functions" in my previous article (link is below) and I will continue writing about it and trying to show you more of the "function" features. On the previous article, you learned, what function is, how do we create a function and how do we call a function. In this article, you will learn what parameters and arguments are and some other parameters we use.
Prerequisites:
Functions Part II:
Argument: The value we pass on to a function. There are two different kinds of arguments: keyword argument and positional argument. In my previous article, you have seen "a" and "b" and you have seen how we pass values on these two variables. If you have noticed that the values I assigned when I called the function was in order. Let´s look at the example again and see what I mean.
Code:
>>>def func(a,b):
>>> return (a*b)
>>>func(5,8)
Output:
Parameter: Parameters are the named entities of arguments we pass on to the function or method. As on the last example above, "b" and "a" are parameters of arguments "5" and "9".
Usually, both arguments and parameters are used as something. So don't worry if you mix the terms.
We can pass a list as an argument to a function or method.
Code:
>>>cars = ["seat", "mazda", "toyota"]
>>>def func(vehicle):
>>> for x in vehicle:
>>> print(x)
>>>my_function(cars)
Output:
seat
mazda
toyota