list element python code example

Example 1: how to make a python list

listName = [1,2,3,4]

Example 2: list of lists python

listOfLists = [[1,2,3],['hello','world'],[True,False,None]]

Example 3: how to make a list python

list = ['list element', 'list element']
# or t obe more effecient:
import numpy #if you do not have numpy, do "pip install numpy"
numpyarray = numpy.array(['array element', 'array element'])
#a numpy array is faster than a standard list

Example 4: python list and list

a = ['apple', 'banana', 'pear']
b = ['fridge', 'stove', 'banana']

a & b == ['banana'] #True

Example 5: making lists in python

# list with numbers
list = [10, 20, 30]
# list with strings
list = ["john", "kai", "albert"]
# mixed data
list = ["john",1 ,True ]

Example 6: lists in python

[0,'',True,5.2,False,[1,2]]