How do you initialize a new list?
new_list = []
or
new_list = list()
How do you initialize a new dictionary?
my_dict = {}
or
my_dict = dict()
What reserved word do you use to initialize a new function?
A. function my_func():
B. def my_func():
C. func my_func():
D. new my_func():
B. def my_func():
True or False, the following code will throw an error...
x, y = 20, 30
print(x, y)
False, you can assign values to multiple variables on one line if separated by a ','
What type of music does Professor Zack like most?
Electronic
Jazz
Rap
Rap
How do you add an element to the end of a list?
append
my_list.append( new_element )
Which way is correct when trying to access the value associated with 'my_key'?
my_dict['my_key']
or
my_dict{'my_key'}
or
my_dict('my_key')
True or False, a function can only return one element?
False, they can return as many elements as you'd like.
def my_func():
return(x, y, z)
True or False, It is python convention to import the library in the line above where you are using the library.
False, it is python convention to import libraries at the very top or in the first lines of your python script.
What are Professor Zacks favorite data structures?
Dictionaries
Lists
Sets
Tuples
[Lists]
What element of the list will this return
my_list[-1]
The element at the end of the list.
When iterating through a dictionary, what will the following 'i' value be, the dictionary keys or the values?
for i in my_dict:
print(i)
the keys
A variable used inside a function becomes its...
A. Global Variable
B. Local Variable
C. Reference Variable
D. None of these
B. Local Variable
What will the following code produce?
my_string = 'A string'
x = list(my_string)
print(x)
A. ['A', ' ', 's', 't', 'r', 'i', 'n', 'g']
B. ['A', 'string']
C. ['A string']
D. None of the above
A. ['A', ' ', 's', 't', 'r', 'i', 'n', 'g']
It will split the string into individual characters.
What does Professor Zack like the least?
Teaching
Pinball
Reading
Skateboarding
Surfing
Reading
If you have two lists of the same size, how do you iterate through both of them simultaneously?
for i, j in zip( list_one, list_two):
print(i, j)
True or False, values in the dictionary have to be unique.
False, the KEYS must be unique, the VALUES do not have to be unique.
True or False, this is a valid way of constructing a function?
def my_func(x=5, y):
return(x)
False, it will throw a error:
SyntaxError: non-default argument follows default argument.
valid way is
def my_func(y, x=5):
return(x)
What will the following code print?
my_string = 'abcdef'
print( my_string[0:-2] )
abcd
Because it will start at the 0th element and go to the -2 element which is d.
Which of the following behavior/s will get you on Zack's 'bad side'?
Interrupt him during class.
Using Google and ChatGPT.
Not doing your HW.
DMing him on Slack.
Not doing your HW.
Which one of these is not a valid list method...
.index()
.length()
.insert()
.sort()
.length()
Which of these is not a valid method of dictionaries?
.values()
.pop()
.append()
.update()
True.
def my_func(x):
return(x)
my_list = []
my_list[0] = my_func
True or False, The following is a valid way to construct a new class?
class Ball():
def __init__(x, y):
self.x = x
self.y = y
False. It is missing the 'self' variable in the init statement.
class Ball():
def __init__(self, x, y):
self.x = x
self.y = y
Which of the following jobs has Professor Zack NOT done.
Financial Statistician at a Hedge Fund
Professional Poker Player
Data Scientist at Google
Line Chef at a Burrito Bar
Head Ocean Lifeguard
Editorial Graphic Designer
Director of Analytics at a Presidential Campaign
Financial Statistician