0
How does the Arguments in a Function Work?
I saw this code for Tic-Tac-Toe with Python on the Internet. IN the winner Function it accepts two arguments (bo, le) which are totally apart from the code. But it still works and I can't understand the arguments in the function of Python. Can anyone explain me about this? Code --> https://code.sololearn.com/c03X4084YoIk/#py
3 ответов
+ 2
In line 51, when isWinner is called, arguments are passed into isWinner()
The arguments passed into isWinner() are boardCopy and let
The parameter in isWinner is named bo and le, and their values are the arguments passed into it.
+ 1
Actually the techincal terms are arguments and parameters.
When defining a function, you put the "parameters" in the parenthesis, for example,
def myFunc(para1, para2) :
Here para1 and para2 are parameter.
Then in your function you do something with the parameters.
For example,
return para1 + para2
Notice that this is applicable to any values and types of para1 and para2
Now, when we call the function, you pass the "arguments" into the function,
For example,
myFunc(1, 2)
is passing integer 1 and 2 into myFunc as arguments
myFunc's parameters para1 and para2 will then have values of 1 and 2 and type of both integer.
And it will perform Maths addition and returns 3.
For another example, if we call myFunc by
myFunc("SoloLearn", "is great!")
The arguments are strings.
So the parameters become string, and string concantention occurs,
returning "SoloLearnis great!" (no space between para1 and para2)
See?
0
Oh man now I figured it out.
Thanks for clearing my doubt.
So an argument with different name can be replaced to bo and le right?