Python Quiz Lists and For Loops Flashcards
The following is an example of a python _______________.
areas = (16, 14, 3, 14, 2, 3)
tuple
Adding items to the end of the list is easy using the ____________ method
append()
Each item in a list is separated by a _______________ punctuation symbol.
comma
If you wanted to permanently remove ‘white’ from this list, but needed to retain a copy to use in your code, you would use _________ to remove the item.
colors = [‘green’, ‘purple’, ‘orange’, ‘red’, ‘blue’, ‘yellow’, ‘white’]
pop()
A python mutable collection that has items that are in a particular order is a(n)_______________.
list
T/F
The difference between a tuple and a list is that a list may be modified and a tuple once created may not be modified unless you completely overwrite the entire tuple.
True
In the following, what is then length of the following list?
games = [‘poker’, ‘spades’, ‘dice’, ‘checkers’, ‘chess’]
5
If you use sort() on a list, the change would be ______.
permanent
The __________ function is used to generate numbers.
range()
If you wanted to find the smallest value in a list of numbers you would use the __________ method.
min()
T/F
Python uses { } to group the statements in a “for loop”.
False
Given the following list, print(colors[ 2: ]) would return which of the following?
colors = [‘green’, ‘purple’, ‘orange’, ‘red’, ‘blue’, ‘yellow’, ‘white’]
[‘orange’, ‘red’, ‘blue’, ‘yellow’, ‘white’]
The statements in a “for loop” are indicated by _____ the statements that should be repeated.
indenting
If you see:
numbers = list(range(2, 14, 2)) you will end up with this list of numbers:
[2, 4, 6, 8, 10, 12]
In the following code snippet, _____ is a variable value that temporarily holds the index value in the for loop.
colors = [‘green’, ‘purple’, ‘orange’, ‘red’, ‘blue’, ‘yellow’, ‘white’]
for color in colors:
print(color)
color