Python Quiz Lists and For Loops Flashcards

1
Q

The following is an example of a python _______________.

areas = (16, 14, 3, 14, 2, 3)

A

tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Adding items to the end of the list is easy using the ____________ method

A

append()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Each item in a list is separated by a _______________ punctuation symbol.

A

comma

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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’]

A

pop()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A python mutable collection that has items that are in a particular order is a(n)_______________.

A

list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

In the following, what is then length of the following list?

games = [‘poker’, ‘spades’, ‘dice’, ‘checkers’, ‘chess’]

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If you use sort() on a list, the change would be ______.

A

permanent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The __________ function is used to generate numbers.

A

range()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

If you wanted to find the smallest value in a list of numbers you would use the __________ method.

A

min()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

T/F

Python uses { } to group the statements in a “for loop”.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Given the following list, print(colors[ 2: ]) would return which of the following?

colors = [‘green’, ‘purple’, ‘orange’, ‘red’, ‘blue’, ‘yellow’, ‘white’]

A

[‘orange’, ‘red’, ‘blue’, ‘yellow’, ‘white’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The statements in a “for loop” are indicated by _____ the statements that should be repeated.

A

indenting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If you see:

numbers = list(range(2, 14, 2)) you will end up with this list of numbers:

A

[2, 4, 6, 8, 10, 12]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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)

A

color

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What would be the values in the list called “numbers” after the following code?
numbers = []

numbers = []
for value in range(1, 8):
number = value**2
numbers.append(number)

A

[1, 4, 9, 16, 25, 36, 49]