Flashcards in Functions Deck (13)
What is decomposition?
Different pieces of self-contained code work together towards a goal
What is abstraction?
Suppressing details of method to compute something as advertised
What are the characteristics of a function?
Keyword, Name, Parameters(optional), Docstring, Body
Optional documentation describing function
#A function must be invoked to run: is_even(3)
What must be used to get a value when using a function?
What is global and function scope?
Global scope is the scope of bound values
Function scope is values that are bound within the function, this does not affect global scope
#Variables assigned values will stay within scope unless referenced in the parameter of another scope
What is the difference between return and print?
Return is used only in function
Only one return is executed in a function, after it breaks from the function
Has a value associated from the function invoking it
What is an internal/helper function?
A function that is evaluated (made) within an existing function
What is important when invoking a function?
Any parameters must also be invoked likewise
Evaluate: def func_a() Invoke: func_a()
Evaluate: def func_b(x,y,z) Invoke: func_b(3,2,4)
How do you give a parameter in a function a default value?
Evaluate: def func_a(a = True, b = False)
print("a is true")
Invoke: func_a() #Parameter does not have to be specified
What is best practice for the function docstring?
Assumptions: conditions that must be met by clients of the function; typically constraints on values of parameters
Guarantees: conditions that must be met by function, providing it has been called in a manner consistent with assumptions
How do you use methods as functions?
What are some built in python methods on strings?