[Tutor] Help!
Cameron Simpson
cs at cskk.id.au
Mon Jan 4 16:18:33 EST 2021
On 04Jan2021 09:38, Weston Batey <3007645 at students.ankenyschools.org> wrote:
>My school is currently using edhesive to do python work and I need help
>answering this question. I am in 8.6 arrays as parameters. A ___________ is
>a variable used to pass information to a method.
The clue's in the title :-)
I'm guessing you're doing this, or something like it:
https://ochoaprep.erusd.org/apps/classes/916418/assignments/
There's a PDF there associated with the Unit 9 quiz.
This is just a terminology question, and since the handout PDF above is
pretty... short on context:
The word you want is "parameter". When you write a function like this:
def mul(a, b):
return a * b
the variables "a" and "b" come from the function argumments, generally
called "parameters". When you call it, for example:
x = mul(3, 2)
the function parameters "a" and "b" take on the values 3 and 2
respectively, which it then multiplies together and returns as the
function result. The calling code above receives that result and stores
it in its own variable "x".
Note that Python variable are _references_. In the larger context of
arrays as parameters, an array variable is a _reference_ to the array
itself in memory. So when you do something like this:
x = [1, 2, 3]
and call a function f(x), the function receives a copy of the
_reference_, not a copy of the array. That reference is pointing to the
same array as the caller, which means that the function may modify the
contents of the array directly and the caller will see the changes.
Also have a read of the python docs:
https://docs.python.org/3/glossary.html?highlight=glossary#term-arguments
https://docs.python.org/3/glossary.html?highlight=glossary#term-parameter
https://docs.python.org/3/faq/programming.html#faq-argument-vs-parameter
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Tutor
mailing list