Lists

Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets

squares = [1, 4, 9, 16, 25] squares
squares = [1, 4, 9, 16, 25] squares[0] #indexing returns the item
squares = [1, 4, 9, 16, 25] squares[-1]
squares = [1, 4, 9, 16, 25] squares[-3:] #slicing returns a new list
squares = [1, 4, 9, 16, 25] len(squares) #length of list

You can add new items at the end of the list by using the append()

cubes = [1, 3, 5, 12, 18, 25] cubes.append(100) cubes