w4 Flashcards

(23 cards)

1
Q

how are modules imported code

A

“import ‘module name’”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is a module

A

file of python code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what must modules be documented with

A

docstrings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

whats a docstring

A

used to describe the purpose and functionality of a specific code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

whats the name of the module when its imported

A

__name__

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

whats the name of the module when its run as the main program

A

__main__

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

whats a namespace

A

a dictionary of names

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

when must default parameters be known

A

when def statement is executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what do variable parameters allow

A

allows functions to be called with any number of arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

2 reasons for writing functions

A
  • make code easier to understand
  • to make code reusable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

2 types of functions

A

procedures and real functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what’s the 3 diff between procedures and real functions

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

3 ways functions arise

A

deliberately through design
during refactoring, when cleaning up a code
by discovery

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what are global variables and where can they be in relation to functions

A

these are variables created outside a function and
can be both inside and outside of functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what are local variables and where can they be in relation to functions

A

these a variables that are created inside functions
can only be accessed inside the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

x = min(7,14,50)

A

finds the minimum value of the iterable

17
Q

x = abs(-7.55573)

A

finds the absolute (positive) value of the specified number

18
Q

x = round(-10.355,2)

A

will round number to digits specified, in this case 2

19
Q

y = pow(2,3,3)

A

returns the value of x to the power of y, the last digit is known as the mod (modulus) which is the remainder

20
Q

y = sum(2,7,84)

A

returns the sum of all the numbers in the iterable

21
Q

math.ceil()

A

rounds a number upwards to its nearest integer

22
Q

math.floor()

A

rounds a number downwards to its nearest integer

23
Q

math.pi