python liste code example
Example 1: list of lists python
listOfLists = [[1,2,3],['hello','world'],[True,False,None]]
Example 2: liste in python
Liste = ['Element1','Element2','Element3']
Example 3: python list
# Create list
List = list()
List = []
List = [0, "any data type can be added to list", 25.12,
("Even tuples"), {"Dictionaries": "can also be added"},
["can", "be nested"]]
# Accessing items
List[1] # 0
List[-1] # ["can", "be nested"]
# Operations
List.append(4) # adds 4 to end
List.pop(n=-1) # removes element from nth position
List.count(25.12) # 1
Example 4: indice d'un element dans une liste python
week = ['monday','tuesday','wednesday']
week.index('tuesday')
>>> 1
"""Warning => error if the element isn't in the list"""