chapter 9 practice questions: Lists Flashcards
What will the following print?
cheeses = [‘Cheddar’, ‘Edam’, ‘Gouda’]
print(‘Edam’ in cheeses)
print(‘Brie’ in cheeses)
- True
- False
What is printed by the following?
alist = [4, 2, 8, 6, 5]
alist[2] = True
print(alist)
[4, 2, True, 6, 5]
What is printed by the following?
alist = [3, 67, “cat”, [56, 57, “dog”], [ ], 3.14, False]
print(57 in alist)
False
What will happen if you attempt to traverse an empty list?
Nothing will happen
How many items are in this list?
nestedList = [[“First”, 2, [“Third”]]]
1
What will the following print?
a = [1, 2, 3]
b = [4, 5, 6]
c = a + b
print(c)
[1, 2, 3, 4, 5, 6]
What does the following print?
print([0] * 4)
print([1, 2, 3] * 3)
[0, 0, 0, 0]
[1, 2, 3, 1, 2, 3, 1, 2, 3]
What will be printed by the following?
alist = [4, 2, 8, 6, 5]
alist = alist + 999
print(alist)
Error, you cannot concatentate a list with an integer
What does the following print?
t = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]
t[1:3] = [‘x’, ‘y’]
print(t)
[‘a’, ‘x’, ‘y’, ‘d’, ‘e’, ‘f’]
What is printed by the following?
alist = [4, 2, 8, 6, 5]
alist.append(True)
alist.append(False)
print(alist)
[4, 2, 8, 6, 5, True, False]
what does .extend() do?
takes a list as an argument and appends all of the elements
What does the following print?
t1 = [‘a’, ‘b’, ‘c’]
t2 = [‘d’, ‘e’]
t1.extend(t2)
print(t1)
[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]
what does .sort() do?
arranges the elements of the list from low to high
True or False? The sort method alphabetizes lists
False
what does .pop() do?
modifies the list and returns the element that was removed