python 9
What is the output of this program? dimensions = [ [12, 3, 5], [45, 7, 8], [1, 2, 3] ] for row in dimensions: for num in row: print(num)
12 3 5 45 7 8 1 2 3
What kind of data structure is user_data in the following declaration? user_data = {"name": "TJ", "age":24, "user_name":"artLover123"}
Dictionary
Use the following definitions of foods and groceries. foods = ["apples", "eel", "kale"] groceries = ["apples", "eel", "kale"] Which of the following statements would evaluate to True about foods and groceries? I. foods == groceries II. foods is groceries
I only
What does "unpacking" refer to in Python?
Initializing multiple variables at a time using a collection of values
What does "packing" refer to in Python?
Storing multiple variables' values by putting them in a collection, like a list or tuple
What does this program print? numbers = [x + x for x in range(4)] print(numbers)
[0, 2, 4, 6]
Given the following list, my_list = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11] ] Python what will be printed when the following line of code is called? print(my_list[3][1:])
[10, 11]
What does the following program print? my_grid = [[2, 5, 7, 10], [-3, "hello", 9, "hi"], ["hello", "hi", "hello", "hi"], [True, False, True, False]] print(my_grid[0])
[2, 5, 7, 10]
What does this program print? numbers = [x % 2 == 0 for x in range(0, 6)] print(numbers)
[True, False, True, False, True, False]
What does the following program print? my_grid = [[2, 5, 7, 10], [-3, "hello", 9, "hi"], ["hello", "hi", "hello", "hi"], [True, False, True, False]] print(my_grid[:2])
[[2, 5, 7, 10], [-3, 'hello', 9, 'hi']]
Which of the following code snippets will create this 2D list? [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
board = [] board.append([1, 2, 3]) board.append([4, 5, 6]) board.append([7, 8, 9])
Which of the following assignment statements is equivalent to the following code snippet? coffee, tea, smoothie = ["kona", "mango", "raspberry"]
coffee = "kona" tea = "mango" smoothie = "raspberry"
A dictionary maps:
keys to values
Which of the following is a correct example of unpacking?
my_list = [1, 2, 3] x, y, z = my_list
Which of the following list comprehensions will create the same list as the for loop below? my_list = [] for i in range(6): my_list.append(i*2)
my_list = [i*2 for i in range(6)]
What is the output of this program? plants = { "tree" : "oak", "flower" : "daisy", "weed" : "bindweed" } for plant in plants: print(plants[plant])
oak daisy bindweed
Suppose you have the following dictionary, which stores the names and ages of people: my_dictionary = { "Bo": 32, "Fiona": 28, "Carlos": 45 } Which line correctly prints Bo's age?
print(my_dictionary["Bo"])
Given the following list, my_list = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11] ] which line of code will print the following output? [[3, 4, 5], [6, 7, 8]]
print(my_list[1:3])
Given the following list, my_list = [ [0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11] ] Which line of code would print the number '5' to the screen?
print(my_list[1][2])
Which of the following assignment statements is equivalent to the following code snippet? red, blue, green = "BLUE", "GREEN", "RED"
red = "BLUE" blue = "GREEN" green = "RED"
Which of the following is a correct example of packing?
x = 1 y = 2 z = 3 my_list = [x, y, z]
Refer to the following program. Are x and y equivalent? x = [1, 2, 3] y = [1, 2, 3]
yes
Refer to the following program. Are x and y equivalent? x = [1, 2, 3] y = x
yes
Refer to the following program. Are x and y identical? x = [1, 2, 3] y = x
yes