Quiz 2 Material Flashcards

1
Q

creating a function

A

def name(parameters):
statements…
return something

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

evaluate

A

turn an expression into a value

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

argument

A

the value/expression we send to a function

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

parameter

A

name we use for the variables in the function (you see them in the header) that are assigned to the arguments

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

call

A

to use a function

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

function definition

A

the code of the function (starts with “def”)

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

return

A

exit the value we exited with

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

side effect

A

actions that a function does (beyond returning something) that affect the environment outside of the function

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

in a function, it is important to _____ a value instead of printing it

A

return

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

def print_a_number(num):
print num

f1 = print_a_number(7)
print f1

A

7
none

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

do values that only existed within a function still remain in the memory after the function call line was executed?

A

no, python removes the memory for the function and those values are gone

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

scope

A
  • the area where the variable is recognized (or has meaning)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

global variables

A

declared outside of a function
(have scope from where they are first created until the end of the program

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

local variables

A

declared inside of a function
(have scope from where they are first created until the end of the function definition, this includes parameters)

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

which variable will be used? -> if the variable name is on the left of an assignment operator, it doesn’t have a value yet and the global operator is not used

A

python treats it as a local variable

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

if the variable is assumed to have a value already:
- if a local variable by that name exists, the _____ variable will be used
- if no local variable by that name exists, the _____ variable will be used

A
  • local
  • global
17
Q

you have to use the global keyword at the beginning of the function to ______ variables

A

modify

18
Q

default parameters

A

def my_function(a, b=15, c=’dog’)
b and c
- gives us the option of providing an argument for a certain parameter
- it we don’t provide an argument for that parameter, the function uses the default argument instead

19
Q

arguments: when you ___ a function
parameters: when you ___ a function

A

call
define

20
Q

which one is the positional argument and which one is the named argument?

my_function(a=10)
my_function(10)

do they do the same thing?

A

first one: named argument
second one: positional argument

yes

21
Q

libraries

A

groups of functions or pre-existing programs you can build from

22
Q

what is the syntax for importing random

A

import random

23
Q

what happens if we forgot to import and we use the a function within the library in our code?

A

there will be a name error that says that ‘—-‘ is not defined

24
Q

what is the syntax for choosing a random integer from 1 to 10 after you have imported random?

A

random.randint(1, 10)

25
Q

boolean

A
  • bool
  • used to denote “truth” and only has 2 possible values: True and False
26
Q

comparison operators

A

< > <= >= == !=

27
Q

boolean operators:

and: True when ___ of the things are true
or: True when ___ of the things are true
not: True when the expression is _____

A
  • all
  • any
  • False
28
Q

operands for the logical operators (and, or, not) must be _______

A

booleans