CHAPTER 8

25 July 2022
4.7 (114 reviews)
35 test answers

Unlock all answers in this set

Unlock answers (31)
question
What are the data items in the list called? a. data b. elements c. items d. values
answer
b. elements
question
Which list will be referenced by the variable number after the execution of the following code? 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]
answer
d. [0, 2, 4, 6, 8]
question
What would you use if an element is to be removed from a specific index? a. del statement b. remove method c. index method d. slice method
answer
a. del statement
question
Invalid indexes do not cause slicing expressions to raise an exception.
answer
TRUE
question
What is the first negative index in a list? a. 0 b. -1 c. -0 d. Size of the string or list minus one
answer
b. -1
question
What method can be used to place an item in the list at a specific index? a. append b. index c. insert d. Add
answer
c. insert
question
What would be the value of the variable list after the execution of the following code? list = [1, 2, 3, 4] list[3] = 10 a. [1, 2, 3, 10] b. [1, 2, 10, 4] c. [1, 10, 10, 10] d. invalid code
answer
a. [1, 2, 3, 10]
question
What method or operator can be used to concatenate lists? a. * b. + c. % d. concat
answer
b. +
question
What would be the value of the variable list2 after the execution of the following code? list1 = [1, 2, 3] list2 = list1 list1 = [4, 5, 6] a. [1, 2, 3] b. [4, 5, 6] c. [1, 2, 3, 4, 5, 6] d. invalid code
answer
b. [4, 5, 6]
question
What would be the value of the variable list2 after the execution of the following code? 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. invalid code
answer
a. [1, 2, 3]
question
When working with multiple sets of data, one would typically use a(n) _____. a. list b. tuple c. nested list d. Sequence
answer
c. nested list
question
The primary difference between a tuple and list is that _____. a. when creating a tuple you don't use commas to separate elements 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
answer
d. once a tuple is created, it cannot be changed
question
What is the advantage of using tuples over lists? a. Tuples are not limited in size. b. Tuples can include any data type as an element. c. Processing a tuple is faster than processing a list. d. There is no advantage.
answer
c. Processing a tuple is faster than processing a list.
question
What method can be used to convert a list to a tuple? a. append b. tuple c. insert d. list
answer
b. tuple
question
What method can be used to convert a tuple to a list? a. append b. tuple c. insert d. list
answer
d. list
question
What would be the value of the variable list after the execution of the following code? 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]]
answer
c. [1, 2, 1, 2, 1, 2]
question
Lists are dynamic data structures such that items may be added to them or removed from them.
answer
TRUE
question
Arrays, which most other programming languages allow, have much more capabilities than list structures.
answer
FALSE
question
A list cannot be passed as an argument to a function.
answer
FALSE
question
The remove method removes all occurrences of the item from a list.
answer
FALSE
question
The sort method rearranges the elements of a list so they appear in ascending or descending order.
answer
FALSE
question
The first step in calculating the average of the values in a list is to get the total of the values.
answer
TRUE
question
Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.
answer
FALSE
question
The index - 1 identifies the last element in a list.
answer
TRUE
question
In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.
answer
TRUE
question
A(n) _______________ is an object that holds multiple items of data.
answer
Sequence
question
Each element in a tuple has a(n) _______________ that specifies its position in the tuple.
answer
Index
question
The built-in function _______________ returns the length of a sequence.
answer
len
question
Tuples are _______________ sequences, which means that once a tuple is created, it cannot be changed
answer
Immutable
question
A(n) _______________ is a span of items that are taken from a sequence.
answer
Slice
question
Lists are _______________, which means their elements can be changed.
answer
Mutable
question
The _______________ method is commonly used to add items to a list.
answer
Append
question
The _______________ exception is raised when a search item is not in the list being searched.
answer
ValueError
question
The _______________ method reverses the order of the items in the list.
answer
Reverse
question
The _______________ function returns the item that has the lowest value in the sequence.
answer
min