liste python code example
Example 1: python list
my_list = ['foo', 4, 5, 'bar', 0.4]
my_nested_list = ['foobar', ['baz', 'qux'], [0]]
my_list[2]
my_list[-1]
my_list[:2]
my_nested_list[2]
my_nested_list[-1]
my_nested_list[1][1]
my_list.append(x)
my_list.extend(iterable)
my_list.insert(i, x)
my_list.remove(x)
my_list.pop([i])
my_list.clear()
my_list.index(x[, start[, end]])
my_list.count(x)
my_list.reverse()
my_list.sort(key=None, reverse=False)
my_list.copy()
Example 2: python lists
thislist = ["apple", "banana", "cherry"]
print(thislist[1])
Example 3: python list and list
a = ['apple', 'banana', 'pear']
b = ['fridge', 'stove', 'banana']
a & b == ['banana']
Example 4: liste in python
Liste = ['Element1','Element2','Element3']
Example 5: lists in python
[0,'',True,5.2,False,[1,2]]
Example 6: 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"""