Python List Methods Flashcards

1
Q

append()

A

Adds an element at the end of the list

list.append(elmnt)

fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.append(“orange”)

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

clear()

A

The clear() method removes all the elements from a list.

list.clear()

fruits = [‘apple’, ‘banana’, ‘cherry’, ‘orange’]
fruits.clear()

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

copy()

A

The copy() method returns a copy of the specified list.

list.copy()

fruits = ['apple', 'banana', 'cherry', 'orange']
x = fruits.**copy**()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

count()

A

The count() method returns the number of elements with the specified value.

list.count(value)

points = [1, 4, 2, 9, 7, 8, 9, 3, 1]
x = points.**count**(9)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

extend()

A

The extend() method adds the specified list elements (or any iterable) to the end of the current list.

list.extend(iterable)

fruits = [‘apple’, ‘banana’, ‘cherry’]
points = (1, 4, 5, 9)
fruits.extend(points)

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

index()

A

The index() method returns the position at the first occurrence of the specified value.

list.index(elmnt)

fruits = [4, 55, 64, 32, 16, 32]
x = fruits.**index**(32)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

insert()

A

The insert() method inserts the specified value at the specified position.

list.insert(pos, elmnt)

fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.insert(1, “orange”)

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

pop()

A

The pop() method removes the element at the specified position.

list.pop(pos)

fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.pop(1)

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

remove()

A

The remove() method removes the first occurrence of the element with the specified value.

list.remove(elmnt)

fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.remove(“banana”)

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

reverse()

A

The reverse() method reverses the sorting order of the elements.

list.reverse()

fruits = [‘apple’, ‘banana’, ‘cherry’]
fruits.reverse()

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

sort()

A

The sort() method sorts the list ascending by default.

list.sort(reverse=True | False, key=myFunc)

cars = [‘Ford’, ‘BMW’, ‘Volvo’]
cars.sort()

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