Sequences and lists Flashcards

1
Q

The _____ method can be used to add an item at a specific index in a list.

insert
add
index
append

A

insert

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

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]

A

[1,3,5,7]

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

The index() method is used to sort the elements of the list in ascending order.

TRUE
FALSE

A

FALSE

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

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

TRUE
FALSE

A

TRUE

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

The slicing operations always create a new sequence. They never modify the original sequence.

TRUE
FALSE

A

TRUE

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

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]

A

[11, 12, 10, 14]

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

Each element in a list has an index that specifies its position in the list.

TRUE
FALSE

A

TRUE

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

Lists in Python are mutable.

TRUE
FALSE

A

TRUE

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

A sequence is an object that contains multiple items of data.

TRUE
FALSE

A

TRUE

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

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.

A

once a tuple is created, it cannot be changed.

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

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

TRUE
FALSE

A

TRUE

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

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

TRUE
FALSE

A

FALSE

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

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

TRUE
FALSE

A

FALSE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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.

TRUE
FALSE

A

TRUE

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

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.

A

Processing a tuple is faster than processing a list.

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 del statement
a slice method
a remove method
an index method
A

a del statement

17
Q

What is the first negative index in a list?

the size of the list minus 1
0
-0
-1
A

-1

18
Q

Which method or operator can be used to concatenate lists?

concat
*
\+
%
A

+

19
Q

What will be the value of the variable list after the following code executes?

list = [1, 2]
list = list * 3
[3, 6]
[1, 2], [1, 2], [1, 2]
[1, 2] * 3
[1, 2, 1, 2, 1, 2]
A

[1, 2, 1, 2, 1, 2]

20
Q

What will be the value of the variable list after the following code executes?

list = [1, 2, 3, 4]
list[3] = 10
[1, 2, 10, 4]
[1, 2, 3, 10]
Nothing; this code is invalid
[1, 10, 10, 10]
A

[1, 2, 3, 10]

21
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]
[4, 5, 6]
Nothing; this code is invalid
[1, 2, 3, 4, 5, 6]
[1, 2, 3]
A

[1, 2, 3]