6 Defining Functions Flashcards
How to import all the functions in a library?
from function import *
What are the two drawbacks of not using functions?
having to write the code twice, the same code has to be maintained at two different places
What is “a function definition”?
A part of the program to creates a function
What does it mean for a function to be “called” or “invoked”?
The function is used in a program
What is “the scope of a variable”?
Refers to the places in a program where a given variable may be referenced
Discuss the scope of variables used inside a function.
They are local to that function.
What is only way for a function to see a variable from another function?
Passing the variable as a parameter
How does “a function definition” look like?
def ():
What are “formal parameters”?
They are variables only accessible in the function body (subset of local variables).
How to call a function?
()
What happens after a function call (five steps)?
(1. Calling program suspends execution.)(2. Function definition is looked up.)(3. Formal parameters get assigned by values of actual parameters.)(4. The function body is executed.)(5. Control returns to the point of function call.)
How are formal and actual parameters matched?
By position
How to use “keyword parameters”?
def ( = ): , ( = ), match my name
Where do fundamental ideas and vocab for functions come from?
From mathematical functions
What two things happen after control reaches “return” statement?
(1. exits and returns to the point of function call.)(2. The value provided in the return statement is sent back to caller.)