python - list 数据类型
随机数 random:
append:
append() method only works for the addition of elements at the end of the List, for the addition of elements at the desired position, insert() method is used. Unlike append() which takes only one argument, the insert() method requires two arguments(position, value).
insert
extend
Other than append() and insert() methods, there’s one more method for the Addition of elements, extend(), this method is used to add multiple elements at the same time at the end of the list.
Note – append() and extend() methods can only add elements at the end.
remove
Elements can be removed from the List by using the built-in remove() function but an Error arises if the element doesn’t exist in the set. Remove() method only removes one element at a time, to remove a range of elements, the iterator is used. The remove() method removes the specified item.
Note – Remove method in List will only remove the first occurrence of the searched element.
pop
Pop() function can also be used to remove and return an element from the set, but by default it removes only the last element of the set, to remove an element from a specific position of the List, the index of the element is passed as an argument to the pop() method.