Posts

Showing posts with the label List

Python List

  List: List   is a collection which is ordered and changeable. Allows duplicate members.  In Python lists are written with square brackets.      list = ["apple", "banana", "cherry"]      print(list)      Output:  ['apple', 'banana', 'cherry'] append():  Adds an element at the end of the list.  extend():   Add all elements of a list to the another list. insert():   Insert an item at the defined index. remove():   Removes an item from the list. pop():   Removes and returns an element at the given index. clear():   Removes all items from the list. index():  Returns the index of the first matched item. len():  To determine how many items a list. negative indexing:  It means beginning from the end, -1 refers to the last item, -2 refers to the second last item etc. slicing:  You can specify a range of indexes by specifying where to start and wh...