Week 7 Flashcards

1
Q

Invalid indexes do not cause slicing expressions to raise an exception.

A

True

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

Lists are dynamic data structures such that items may be added to them or removed from them.

A

True

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

Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures.

A

False

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

A list cannot be passed as an argument to a function.

A

False

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

The remove method removes all occurrences of an item from a list.

A

False

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

The sort method rearranges the elements of a list so they are in ascending or descending order.

A

False

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

The index of the first element in a list is 1, the index of the second element is 2, and so forth.

A

False

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

The index -1 identifies the last element in a list.

A

True

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

To calculate the average of the numeric values in a list, the first step is to get the total of values in the list.

A

True

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

In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.

A

True

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

What are the data items in a list called?
a. data
b. elements
c. items
d. values

A

b. elements

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

When working with multiple sets of data, one would typically use a(n)
a. list
b. tuple
c. nested list
d. sequence

A

c. nested list

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

The primary difference between a tuple and a list is that
a. you don’t use commas to separate elements in a tuple
b. a tuple can only include string elements
c. a tuple cannot include lists as elements
d. once a tuple is created, it cannot be changed

A

d. once a tuple is created, it cannot be changed

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

What is an advantage of using a tuple rather than a list?
a. Tuples are not limited in size.
b. Tuples can include any data as an element.
c. Processing a tuple is faster than processing a list.
d. There is never an advantage to using a tuple.

A

c. Processing a tuple is faster than processing a list.

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

Which list will be referenced by the variable number after the following code is executed?
number = range(0, 9, 2)
a. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
b. [1, 3, 5, 7, 9]
c. [2, 4, 6, 8]
d. [0, 2, 4, 6, 8]

A

d. [0, 2, 4, 6, 8]

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

Which of the following would you use if an element is to be removed from a specific index?
a. a del statement
b. a remove method
c. an index method
d. a slice method

A

a. del statement

17
Q

What is the first negative index in a list?
a. 0
b. -1
c. -0
d. the size of the list minus 1

A

b. -1

18
Q

Which method can be used to place an item at a specific index in a list?
a. append
b. index
c. insert
d. add

A

c. insert

19
Q

Which method or operator can be used to concatenate lists?
a. *
b. +
c. %
d. concat

A

b. +

20
Q

Which method can be used to convert a list to a tuple?
a. append
b. tuple
c. insert
d. list

A

b. tuple

21
Q

Which method can be used to convert a tuple to a list?
a. append
b. tuple
c. insert
d. list

A

d. list

22
Q

What will be the value of the variable list after the following code executes?
list = [1, 2]
list = list * 3
a. [1, 2] * 3
b. [3, 6]
c. [1, 2, 1, 2, 1, 2]
d. [1, 2], [1, 2], [1, 2]

A

c. [1, 2, 1, 2, 1, 2]

23
Q

What will be the value of the variable list after the following code executes?
list = [1, 2, 3, 4]
list[3] = 10
a. [1, 2, 3, 10]
b. [1, 2, 10, 4]
c. [1, 10, 10, 10]
d. Nothing; this code is invalid

A

a. [1, 2, 3, 10]

24
Q

What will be the value of the variable list2 after the following code executes?
list1 = [1, 2, 3]
list2 = []
for element in list1:
list2.append(element)
list1 = [4, 5, 6]
a. [1, 2, 3]
b. [4, 5, 6]
c. [1, 2, 3, 4, 5, 6]
d. Nothing; this code is invalid

A

a. [1, 2, 3]

25
Q

What will be the value of the variable list2 after the following code executes?
list1 = [1, 2, 3]
list2 = []
list1 = [4, 5, 6]
a. [1, 2, 3]
b. [4, 5, 6]
c. [1, 2, 3, 4, 5, 6]
d. Nothing; this code is invalid

A

b. [4, 5, 6]

26
Q

A(n) __________ is an object that holds multiple items of data.

A

sequence

27
Q

Each element in a tuple has a(n) __________ that specifies its position in the tuple.

A

index

28
Q

The built-in function __________ returns the length of a sequence.

A

len

29
Q

Tuples are __________ sequences which means that once a tuple is created, it cannot be changed.

A

immutable

30
Q

A(n) ___________ is a span of items that are taken from a sequence.

A

slice

31
Q

Lists are ___________, which means their elements can be changed in a program.

A

mutable

32
Q

The __________ method is commonly used to add items to a list.

A

append

33
Q

The __________ exception is raised when a search item is not in the list being searched.

A

ValueError

34
Q

The __________ method reverses the order of the items in a list.

A

reverse

35
Q

The __________ function returns the item that has the lowest value in the sequence.

A

min

36
Q

The ___________ function can be used to convert a list to a tuple.

A