Which method is used to add a single item to the end of a list?
A
add() B
insert() C
append() D
extend()
Analysis & Theory
The append() method adds a single element to the end of the list.
What will be the result of my_list = [1, 2]; my_list.append(3) ?
A
[1, 2] B
[1, 2, 3] C
[3, 1, 2] D
[1, 2] [3]
Analysis & Theory
append() adds 3 to the end, so the list becomes [1, 2, 3].
What does my_list.insert(1, 99) do?
A
Adds 99 at the beginning B
Adds 99 at index 1 C
Adds 99 at the end D
Replaces the item at index 1
Analysis & Theory
insert(index, value) inserts the value at the given position, shifting other items.
Which method adds all elements of a list to another list?
A
append() B
add() C
merge() D
extend()
Analysis & Theory
extend() adds each element of the passed list to the original list.
What will be the result of [1, 2] + [3, 4] ?
A
[1, 2, 3, 4] B
[1, 2, [3, 4]] C
[4, 5, 6] D
[1, 2] + [3, 4]
Analysis & Theory
Using + with lists concatenates them into a new list.
What will happen if you use append([4, 5]) on my_list = [1, 2, 3] ?
A
[1, 2, 3, 4, 5] B
[1, 2, 3, [4, 5]] C
[1, 2, 3, 4] D
Error
Analysis & Theory
append() adds the entire list as a single element, creating a nested list.
What is the result of my_list.extend('abc') ?
A
Adds 'abc' as one item B
Adds ['abc'] C
Adds ['a', 'b', 'c'] D
Raises an error
Analysis & Theory
extend() breaks the string into characters and adds each to the list.
Which method allows inserting an item at a specific index?
A
append() B
extend() C
insert() D
add()
Analysis & Theory
insert(index, value) places the value at the specified index in the list.
How can you add multiple elements at once to a list?
A
append() multiple times B
use extend() C
use + operator D
All of the above
Analysis & Theory
You can add multiple items using extend(), + operator, or repeated append().
Which operation will create a new list without modifying the original?
A
my_list.append(5) B
my_list += [5] C
my_list + [5] D
my_list.extend([5])
Analysis & Theory
Using + creates a new list; it doesn't modify the original unless reassigned.