list=[1,2,3,'abc',True,[5,6,7]]
list
The list above contains 6 elements.
Lets see some of the functions we can use on lists
#Tells us a size of list
len(list)
#Elements of list can be retrieved using index, index starts at 0
list[3]
#Here we are fetching element 0 of element 5
list[5][0]
Adding elements to list can be done by either using append or extend
list.append([100,200,300])
# As you can see append adds the list as list at the end of the original list
list
list.extend([100,200,300])
#Extend on the other hand will append these elements as individual elements
list
#Creates a copy of list
list2=list.copy()
list2
#Empties the list
list2.clear()
list2
#Removes the last element of list
list.pop()
list
#Reverses the list
list.reverse()
list
#Counts the occurence of element
list3=[1,2,1,4,5]
list3.count(1)
#Sorts the list
list3.sort()
list3
#Inserts an element--In this case inserting 100 at index 5
list3.insert(5,100)
list3
#Delete an element at index 5
del list3[5]
list3
#Remove an element 5
list3.remove(5)
list3
#Change the value at certain index in list
list3[0]=-1
list3
#Returns the index of the element we are searching
list3.index(4)