1/88
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
A ___________ is an object that holds multiple items of data, stored one after the other. You can perform operations on a sequence to examine and manipulate the items stored in it.
sequence
A _______ is mutable: the program can change it's contents.
list
A ________ is immutable: once created, the contents cannot be changed
tuple
Lists are dynamic data structures, meaning that items may be added or removed from them. (True or False)
True
Each item in a list is called a(n) __________.
element
even_numbers = [2, 4, 6, 8, 10]
is an example of what?
list
A list can hold items of different types? (True or False)
True
Is the code below representative of a repetition operator?
num = [1, 2, 3]
x = 5
num * x
yes
A _______________ makes multiple copies of a list and joins them all together.
repetition operator
You can iterate over a list with a for loop? (True or False)
True
Each element in a list has a ________ that specifies its' position in the list.
index
What number does indexing start at?
0
What number would the final term in a list be indexed at?
The number of items in the list minus 1.
You can't use negative indexes to reference elements in a list. (True or False)
False
An ____________ will be raised when you use an invalid index with a list.
IndexError
What value will the following code return?
my_list = [a, b, c, d, e, f]
size = len(my_list)
6
What is the output of the following code?
list1 = [a, b, c]
list2 = [d, e, f]
list3 = list1 + list2
print(list3)
[a, b, c, d, e, f]
What is the value of list1 after the following code?
list1 = [a, b]
list2 = [c, d]
list += list2
[a, b, c, d]
You can concatenate lists with any other type of data. (True or False)
False
What will the following code display?
numbers = [1, 2, 3, 4, 5]
numbers[2] = 99
print(numbers)
[1, 2, 99, 4, 5]
What will the following code display?
numbers = list(range(3))
print(numbers)
[ 0, 1, 2]
What will the following code display?
numbers = [10] * 5
print(numbers)
[10, 10, 10, 10, 10]
What will the following code display?
numbers = list(range(1, 10, 2))
for n in numbers:
print(n)
1
3
5
7
9
What will the following code display?
numbers = [1, 2, 3, 4, 5]
print(numbers[-2])
4
How do you find the number of elements in a list?
Using the len() function.
What will the following code display?
numbers1 = [1, 2, 3]
numbers2 = [10, 20, 30]
numbers3 = numbers1 + numbers2
print(numbers1)
print(numbers2)
print(numbers3)
[1, 2, 3]
[10, 20, 30]
[1, 2, 3, 10, 20, 30]
What will the following code display?
numbers1 = [1, 2, 3]
numbers2 = [10, 20, 30]
numbers2 += numbers1
print(numbers1)
print(numbers2)
[1, 2, 3]
[10, 20, 30, 1, 2, 3]
A ________ is a span of items that are taken from a sequence.
slice
What prints out in the following code?
days = [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
mid_days = days[2:5]
print(mid_days)
['Tuesday', 'Wednesday', 'Thursday']
The first element of a list is what number index?
0
In the example below, what will print out?
li = [1, 2, 3, 5]
li_section = li[1:3]
print(li_section)
[2, 3]
If you leave out the start index when slicing an expression, Python uses __ as the starting index.
0
If you leave out the end index when slicing an expression, Python uses _____________ as the end index.
The length of the list.
Invalid indexes cause slicing expressions to raise an exception. (True or False)
False
If the end index specifies a position beyond the end of the list, an exception will be raised. (True or False)
False
If the start index specifies a position before the beginning of the line, Python will use 0 instead. (True or False)
True
If the start index is greater than the end index, the expression will return a(n) ___________.
empty list
What will the following code display?
numbers = [1, 2, 3, 4, 5]
my_list = numbers[1:3]
print(my_list)
[2, 3]
What will the following code display?
numbers = [1, 2, 3, 4, 5]
my_list = numbers[:1]
print(my_list)
[1]
What will the following code display?
numbers = [1, 2, 3, 4, 5]
my_list = numbers[1:]
print(my_list)
[2, 3, 4, 5]
What will the following code display?
numbers = [1, 2, 3, 4, 5]
my_list = numbers[:]
print(my_list)
[1, 2, 3, 4, 5]
What will the following code display?
numbers = [1, 2, 3, 4, 5]
my_list = numbers[-3:]
print(my_list)
[3, 4, 5]
You can search for an item in a list using the __ operator.
in
What will the following code display?
names = ['Jim', 'Jill', 'John', 'Jasmine']
if 'Jasmine' not in names:
print('Cannot find Jasmine')
else:
print('Jasmines family:')
print(names)
['Jim', 'Jill', 'John', 'Jasmine']
_______ have numerous methods that allow you to work with the elements that they contain. Python also provides some built-in functions that are useful for working with _____.
lists
This list method adds the item passed to its argument to the end of a list.
append
This list method returns the index of the first list element whose value is equal to the item passed to its argument.
index
When using an index method on a list, if the item passed as an argument to the function is not found in the list, a ValueError is raised. (True or False)
True
When using the insert method, if you specify an index beyond the end of the list, the item will be inserted into the _____ of the list.
end
When using the insert method, if you specify a negative number with an invalid index, the item will be inserted into the _____ of the list.
beginning
The ______ method inserts an item into the list at a specified index.
insert
The _____ method sorts the items in a list so they appear in ascending order.
sort
The _______ method removes the first occurrence of an item from the list. If the item is not found, a ValueError is raised.
remove
If you want to remove an item at a specific index in a list, you would use the ___ statement.
del
If you want to return the highest value in a list, you would use the ___ statement.
max
If you want to return the lowest value in a list, you would use the ___ statement.
min
Calling a remove statement in a list removes the element at a specified index. (True or False)
False
Calling a del statement in a list removes the element at a specified index. (True or False)
True
How do you find the lowest value in a list?
min()
How do you find the largest value in a list?
max()
Which of the following statements would you use to add the string 'Wendy' to the list at index 0?
name = []
a. names[0] = 'Wendy'
b. names.append('Wendy')
b
A ____________________ list is a list that has other lists as its elements.
two-dimensional
Two-dimensional lists are also called ________ lists.
nested
A _______ is an immutable sequence, which mean that it's content cannot be changed.
tuple
Tuples are enclosed in ___________.
parentheses
Lists are enclosed in ________.
brackets
Tuples support the same operations as lists, except those that change the content of the list. (True or False)
True
A list is processed faster than a tuples. (True or False)
False
Data in a tuple can be changed. (True or False)
False
Some operations in Python require a tuple. (True or False)
True
What function would you use to convert a tuple to a list?
list()
What function would you use to convert a list to a tuple?
tuple()
What command would you use for matplotlib?
import matplotlib
Each function call when you import matplotlib, must be prefixed by __________?
matplotlib.pyplot
If you want to use the plt prefix to call functions, what statement would you write to import matplotlib?
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt allows you to use which prefix to call functions?
plt
In order to create a line graph in matplotlib, you must create two separate lists for the x and y coordinates. (True or False)
True
To create a graph in matplotlib, we would call the ______function.
plot()
What command would you use to show the graph in matplotlib?
plt.show()
What function would you use to create a title for a graph?
plt.title()
What would you use to remove an element from a specific index?
del()
When working with multiple sets of data, one would typically use a(n)
nested list
The sort method rearranges the elements of a list so they are in ascending or descending order. (True or False)
False
The remove method removes all occurrences of an item from a list. (True or False)
False
What method can be used to place an item at a specific index in a list?
insert()
What method or operator can be used to concatenate lists?
+
What is the first negative index in a list?
-1
What list will be reference by the variable number after the following code is executed?
number = range(0, 9, 2)
[0, 2, 4, 6, 8]
A list cannot be passed as an argument to a function. (True or False)
False