Python's way of working / 8. Standard Deviation


#1

Hey there!

this is the instruction:

Define a function, grades_std_deviation, that takes one argument called variance.

return the result of variance ** 0.5

After the function, create a new variable called variance and store the result of calling grades_variance(grades).

Here’s relevant part of the code, which works fine:

def grades_std_deviation(variance):
  return variance ** 0.5

variance = grades_variance(grades)

My question: How can python run the function (def grades_std_deviation) without knowing the variable variance since the variable comes after?

So this is a generally question about how python works.

Thanks in advance!
CR


#2

function parameters and arguments is not a python specific concept, its a concept found in many (if not all) programming languages

in your code, variance is the parameter (provided when you define the function)

grades is the argument, provided at function call

Functions only execute when called, so until the function is called, the parameter is just a placeholder. Then when the function is called, the parameter gets its value from argument at function call


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.