For any queries you can reach us at / WhatsApp us: +919158876092

Python List

Python List

A list is created by placing all the elements inside square brackets [], and separated by commas (,).

numbers = [1, 2, 3, 4]

words = ['five', 'six']

mixed = [1, 2, 'three', 4, 5, 'six', 7.0, 8.0]
Function Description
list.append() Add an item at end of a list
list.extend() Add multiple items at the end of a list
list.insert() insert an item at a defined index
list.remove() remove an item from a lsit
del list[index] delete an item from a list
list.clear() empty all the list
list.pop() remove an item at a defined index
list.index() return index of the first matched item
list.sort() sort the items of a list in ascending or descending order
list.reverse() reverse the items of a list
len(list) return total length of the list
max(list) return item with maximum value in the list
min(list) return item with the minimum value in the list
list(seq) converts a tuple, string, set, dictionary into a list