List Methods :
lst = [1, 2, 3]
lst.append(4) # [1, 2, 3, 4]
lst.extend([5, 6]) # [1, 2, 3, 4, 5, 6]
lst.insert(1, 10) # [1, 10, 2, 3, ...]
lst.remove(10) # Removes first match
lst.pop() # Removes last and returns it
lst.pop(1) # Removes and returns index 1
lst.clear() # []
lst.index(3) # Returns index of 3
lst.count(2) # Count of 2s
lst.sort() # In-place sort
lst.reverse() # In-place reverse
sorted(lst) # Returns sorted copy
No comments:
Post a Comment