Coming soon…

Author

Karl Gregory

The Python List

The list is the basic type of “container” object in Python:

x = [1,2,3]
type(x)
list
y = ["a", "b", "c"]
type(y)
list
z = [True, False, False, True]
type(z)
list

We can access list elements using square brackets. Note that the first entry is indexed at 0:

y[1]
'b'
y[0]
'a'

A Python list does not have to have elements all of one type:

v = [True, 0, "whatever",[1,2]]
type(v[2])
%timeit sum(x)
37.7 ns ± 0.0464 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)