Python List Methods

list = [1,2,3,4,5,]
list.append(6) # [1, 2, 3, 4, 5, 6]
print(list)

list = [1,2,3,4,5,]
list.clear() # []
print(list)

list = [1,2,3,4,5,]
newlist = list.copy()
print(newlist) # [1, 2, 3, 4, 5]

list = [1,1,1,2,]
print(list.count(1)) # 3

list = [1,2,3,4,5,]
list.extend([6,7,8]) # [1, 2, 3, 4, 5, 6, 7, 8]
print(list)

list = [1,2,3,4,5,]
print(list.index(3)) # 2

list = [1,2,3,4,5,]
list.insert(2, 99)
print(list) # [1, 2, 99, 3, 4, 5]

list = [1,2,3,4,5,]
list.pop(2)
print(list)

list = [1,2,3,4,5,]
list.remove(2)
print(list) # [1, 3, 4, 5]

list = [1,2,3,4,5,]
list.reverse()
print(list) # [5, 4, 3, 2, 1]

list = [5,4,3,2,1,]
list.sort()
print(list) # [1, 2, 3, 4, 5]

 

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
3 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.