List in Python | Adding item | Removing item | Length of List | Frequency of an Element |Sorting of list |Conversion from list to string
Creating list list1 = ["first","second","Third"] print(list1) list2 = [1,2,3,4] print(list2) Accessing elements of list We should keep in mind that first element in a list is referred as the 0th element second as 1st and so on. X = list1[0] Y = list2[0] print(X) print(Y) Changing element value list1[1] = "forth" #position of element is given list2[2] = 4 Adding element in list At last of list list1.append("fifth") list2.append(5) At specific position listname.append(position,value) list1.insert(3,"sixth") list2.insert(3,6) Removing element of a list Using list.remove() this method remove element with its value list1.remove("second") list2.remove(2) using pop() method this method remove element at specified position.If position is not mentioned method will remove the last element. list1.pop(2) list2.pop(3