Week 7 Flashcards
Invalid indexes do not cause slicing expressions to raise an exception.
True
Lists are dynamic data structures such that items may be added to them or removed from them.
True
Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures.
False
A list cannot be passed as an argument to a function.
False
The remove method removes all occurrences of an item from a list.
False
The sort method rearranges the elements of a list so they are in ascending or descending order.
False
The index of the first element in a list is 1, the index of the second element is 2, and so forth.
False
The index -1 identifies the last element in a list.
True
To calculate the average of the numeric values in a list, the first step is to get the total of values in the list.
True
In slicing, if the end index specifies a position beyond the end of the list, Python will use the length of the list instead.
True
What are the data items in a list called?
a. data
b. elements
c. items
d. values
b. elements
When working with multiple sets of data, one would typically use a(n)
a. list
b. tuple
c. nested list
d. sequence
c. nested list
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
d. once a tuple is created, it cannot be changed
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.
c. Processing a tuple is faster than processing a list.
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]
d. [0, 2, 4, 6, 8]