Hello I’m just wondering about something in Python3.x.
What is the foo in def function(foo): used for when you can use def function(): too?
I know there is a difference, I just don’t understand the definitions I have found in various books and tutorials.
It’s easier to show than to explain, here’s an example:
This function will ALWAYS print
Hello, regardless on the user. Now take a look at this function:As you can see, we’re printing
foo(called function parameter) instead of a string. This way, when we call the function, we can (and in this case, we must) replace thefooin the function call with any value, and that value will be set tofoo. It’s basically a local variable inside the function, which will be defined by the user when the function is called.Few examples: