Python List Methods Flashcards
1
Q
Adds an element at the end of the list.
A
append()
list = [1, 2, 3] list.append(4) # Output [1, 2, 3, 4]
2
Q
Removes all the elements from the list.
A
clear()
list = [1, 2, 3] list.clear() # Output []
3
Q
Returns a copy of the list.
A
copy()
list = [1, 2, 3] copied_list = list.copy() # Output [1, 2, 3]
4
Q
Returns the number of elements with the specified value.
A
Output
count()
~~~
list = [1, 2, 3, 3]
total_count = list.count(3)
2
5
Q
Add the elements of a list (or any iterable), to the end of the current list.
A
extend()
6
Q
Returns the index of the first element with the specified value.
A
index()
7
Q
Adds an element at the specified position.
A
insert()
8
Q
Removes the element at the specified position.
A
pop()
9
Q
Removes the first item with the specified value.
A
remove()
10
Q
Reverses the order of the list.
A
reverse()
11
Q
Sorts the list.
A
sort()