List Methods in Python

here are in-built methods ,used to remove,add ,count elements and more

MethodDescription
insert(index, item)inserts an item at the specified index,if the index given is not in the list,then item is added to end of the list
append(item)adds an item to the end of the list.
count(item)returns the number of times an item appears in the list.
remove(item)removes the first occurrence of the specified item from the list
reverse()reverse the order of elements in the list.
pop([index])removes element specified in the index,if not specified than last element will be deleted
name = ["kong","alex","jay","gunna","lilkeed"]
name.insert(2,"john")
['kong', 'alex', 'john', 'jay', 'gunna', 'lilkeed']
name.append("jane")
['kong', 'alex', 'john', 'jay', 'gunna', 'lilkeed', 'jane']
name.count("alex")
1
name.remove("alex")
['kong', 'jay', 'gunna', 'lilkeed']
name.reverse()
['lilkeed', 'gunna', 'jay', 'kong']
name.pop(2) #jay
['kong', 'alex', 'gunna', 'lilkeed']
Last updated on by vishal devxo