Methods of Python List
append(item):
Description: Adds an item to the end of the list.
Example:
lst = [1, 2, 3]
[Link](4) # [1, 2, 3, 4]
extend(iterable):
Description: Extends the list by appending elements from the given iterable.
Example:
lst = [1, 2, 3]
[Link]([4, 5]) # [1, 2, 3, 4, 5]
insert(index, item):
Description: Inserts an item at the specified index.
Example:
lst = [1, 2, 3]
[Link](2, 10) # [1, 2, 10, 3]
remove(item):
Description: Removes the first occurrence of the specified item.
Example:
lst = [1, 2, 3, 4]
[Link](3) # [1, 2, 4]
pop(index):
Description: Removes and returns the item at the specified index.
Example:
lst = [1, 2, 3]
item = [Link]() # 3, lst = [1, 2]
clear():
Description: Removes all elements from the list.
Example:
lst = [1, 2, 3]
[Link]() # []
reverse():
Description: Reverses the elements of the list in place.
Example:
lst = [1, 2, 3]
[Link]() # [3, 2, 1]
sort(key=None, reverse=False):
Description: Sorts the list in ascending order by default.
Example:
lst = [3, 1, 2]
[Link]() # [1, 2, 3]
index(item, start=0, end=len(list)):
Description: Returns the index of the first occurrence of the specified item.
Example:
lst = [1, 2, 3]
index = [Link](2) # 1
count(item):
Description: Returns the number of occurrences of the specified item.
Example:
lst = [1, 2, 2, 3]
count = [Link](2) # 2
copy():
Description: Returns a shallow copy of the list.
Example:
lst = [1, 2, 3]
lst_copy = [Link]() # [1, 2, 3]