w4 Flashcards
(23 cards)
how are modules imported code
“import ‘module name’”
what is a module
file of python code
what must modules be documented with
docstrings
whats a docstring
used to describe the purpose and functionality of a specific code
whats the name of the module when its imported
__name__
whats the name of the module when its run as the main program
__main__
whats a namespace
a dictionary of names
when must default parameters be known
when def statement is executed
what do variable parameters allow
allows functions to be called with any number of arguments
2 reasons for writing functions
- make code easier to understand
- to make code reusable
2 types of functions
procedures and real functions
what’s the 3 diff between procedures and real functions
procedures don’t return value to caller (return statement) whilst real function have a return statement
procedures do print output but real functions don’t print output (they write files)
procedure names start with verbs “print”, “compute”
real function names start with nouns
“standard”, “noun”
3 ways functions arise
deliberately through design
during refactoring, when cleaning up a code
by discovery
what are global variables and where can they be in relation to functions
these are variables created outside a function and
can be both inside and outside of functions
what are local variables and where can they be in relation to functions
these a variables that are created inside functions
can only be accessed inside the function
x = min(7,14,50)
finds the minimum value of the iterable
x = abs(-7.55573)
finds the absolute (positive) value of the specified number
x = round(-10.355,2)
will round number to digits specified, in this case 2
y = pow(2,3,3)
returns the value of x to the power of y, the last digit is known as the mod (modulus) which is the remainder
y = sum(2,7,84)
returns the sum of all the numbers in the iterable
math.ceil()
rounds a number upwards to its nearest integer
math.floor()
rounds a number downwards to its nearest integer
math.pi
returns pi