Functions Flashcards Preview

6.00.1x > Functions > Flashcards

Flashcards in Functions Deck (13)
Loading flashcards...
1

What is decomposition?

Different pieces of self-contained code work together towards a goal

2

What is abstraction?

Suppressing details of method to compute something as advertised

3

What are the characteristics of a function?

Keyword, Name, Parameters(optional), Docstring, Body

def is_even(i):
"""
Optional documentation describing function
"""
return(i)
#A function must be invoked to run: is_even(3)

4

What must be used to get a value when using a function?

return

5

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

6

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

7

What is an internal/helper function?

A function that is evaluated (made) within an existing function

8

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)

9

How do you give a parameter in a function a default value?

Bind it
Evaluate: def func_a(a = True, b = False)
if a:
print("a is true")
Invoke: func_a() #Parameter does not have to be specified

10

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

11

How do you use methods as functions?

Dot notation

s.capitalize

12

What are some built in python methods on strings?

.upper()
.capitalize()
.isupper()
.islower()
.swapcase()
.index('i')
.find('i')
.count('i')
.replace('i','e')

13

What is recursion?

Recursion is a way of coding a problem in which function calls itself within its own body