Sequences and lists Flashcards
The _____ method can be used to add an item at a specific index in a list.
insert
add
index
append
insert
Which list will be referenced by the variable number after the following code is executed
number=list(range(1,9,2))
[1,3,5,7,9]
[1,9,2]
[1,3,5,7]
[2,4,6,8]
[1,3,5,7]
The index() method is used to sort the elements of the list in ascending order.
TRUE
FALSE
FALSE
The index -1 identifies the last element in a list.
TRUE
FALSE
TRUE
The slicing operations always create a new sequence. They never modify the original sequence.
TRUE
FALSE
TRUE
What will be the value of the variable x after the following code executes?
x = [11, 12, 13, 14]
x [-2] = 10
[11, 12, 13, -2]
[11, 12, 10, 14]
[11, 12, -2, 10]
[11, 12, 13, 10]
[11, 12, 10, 14]
Each element in a list has an index that specifies its position in the list.
TRUE
FALSE
TRUE
Lists in Python are mutable.
TRUE
FALSE
TRUE
A sequence is an object that contains multiple items of data.
TRUE
FALSE
TRUE
The primary difference between a tuple and a list is that
a tuple cannot include lists as elements.
a tuple can only include string elements.
once a tuple is created, it cannot be changed.
commas cannot be used to separate elements in a tuple.
once a tuple is created, it cannot be changed.
Invalid indexes do not cause slicing expressions to raise an exception.
TRUE
FALSE
TRUE
Arrays, which are allowed by most other programming languages, have more capabilities than Python list structures.
TRUE
FALSE
FALSE
The remove method removes all occurrences of an item from a list.
TRUE
FALSE
FALSE
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
FALSE
TRUE
What is an advantage of using a tuple rather than a list?
Tuples are not limited in size.
There is never an advantage to using a tuple.
Processing a tuple is faster than processing a list.
Tuples can include any data as an element.
Processing a tuple is faster than processing a list.