Making some list...
somelist = ['cat', 'mouse', 'elephant']
Append adds an element at the end of the list
somelist.append('starfish')
print(somelist)
Insert can add the element at any index we specify
somelist.insert(1, 'lion')
print(somelist)
remove method removes the element given, irrespective of the index of that element in the list
somelist.remove('mouse')
print(somelist)
Keep in mind that remove method only removes one element, when it first encounters it
Illustrating this with example below
al = ['remove this','b','c','remove this','d','remove this']
al.remove('remove this')
al
As you can see, it removed the element on it's first encounter which is from left to right.
Sort sorts the list, according to whether the list contains strings or numbers. Sort does not work on lists having both strings and integers.
numberlist = [2,4,5,3,5,6,7,5,4,2]
numberlist.sort()
numberlist
The capital letters come before small letters, as python uses 'ASCII-Betical' order, where capital letters all come before small letters
abclist = ['Cat','cat','dog','Dog','bat','Bat','tiger']
abclist.sort()
abclist
To sort in true alphabetical order, we do the following
abclist.sort(key=str.lower)
abclist
WARNING - We don't do something like following!
abclist = abclist.sort()
Methods have return value of None, so what the above code did, is that it assigned the None value to the abclist, vanishing the entire list!
print(abclist)