Python list objects has many built in methods.
The following are the details of each list method with examples:
s.append(x) - appends x to the end of the sequence
>>> s = ["this", "is", "python"]
>>> s.append("easy")
>>> s
['this', 'is', 'python', 'easy']
s.extend(t) or s += t - extends s with the contents of t
>>> s = ["this", "is", "python"]
>>> s.extend(["easy", ".com"])
>>> s
['this', 'is', 'python', 'easy', '.com']
The argument for extend can be any iterable like tuple
>>> s.extend((".org", ))
>>> s
['this', 'is', 'python', 'easy', '.com', '.org']
s.insert(i, x) inserts x into s at the index given by i
>>> s = ["this", "python"]
>>> s.insert(1, "is") # Inserts at index 1
>>> s
['this', 'is', 'python']
>>> s.insert(-1, "programming") # Inserts at last index
>>> s
['this', 'is', 'programming', 'python']
s.pop(i) retrieves the item at i and also removes it from s
>>> s = ["this", "is", "python", "easy",".com"]
>>> s.pop(1)
'is'
>>> s
['this', 'python', 'easy', '.com']
>>> s.pop(-2)
'easy'
>>> s
['this', 'python', '.com']
s.remove(x) - remove the first item from s where s[i] is equal to x
>>> s = ["this", "is", "pythoneasy.com"]
>>> s.remove("pythoneasy.com")
>>> s
['this', 'is']
>>> s.remove("pythoneasy.com")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list
ValueError is raised if element not found
s.count() counts number times an element present inside the list
>>> s = [34, 56, 78, 23, 67, 23, 42]
>>> s.count(23)
2
s.clear() - removes all items from s (same as del s[:])
>>> s = ["this", "is", "python", "easy",".com"]
>>> s
['this', 'is', 'python', 'easy', '.com']
>>> s.clear()
>>> s
[]
The name will be defined as "l" here, but the contents of the list will be empty
s.copy() creates a shallow copy of s (same as s[:])
>>> s = ["this", "is", "python", "easy",".com"]
>>> l = s.copy()
>>> l
['this', 'is', 'python', 'easy', '.com']
>>> l is s
False
>>> l == s
True
"l" will be a copy of "s"
s.reverse() reverses the items of s in place
>>> s = ["this", "is", "python", "easy",".com"]
>>> s.reverse()
>>> s
['.com', 'easy', 'python', 'is', 'this']
s.sort() It sorts elements of the list in place
>>> s = [13, 423, 2134, 4, 56, 78]
>>> s.sort()
>>> s
[4, 13, 56, 78, 423, 2134]
Comment here