List FunctionsΒΆ
Python has several functions that can take lists as inputs. We will present four such functions here.
len()
returns the number of items in the list.sum()
returns the sum of the elements in a list. This only works on numerical lists.max()
returns the largest item in the list.min()
returns the smallest item in the list.
We will illustrate the use of these functions using the two lists below.
names = ['beth', 'drew', 'fred', 'chad', 'anna', 'emma']
sales = [126, 81, 135, 114, 163, 92]
# Find the length of the lists.
print(len(names))
print(len(sales))
6
6
# Sum the sales list.
print(sum(sales))
711
# Find min and max of names list.
print(min(names))
print(max(names))
anna
fred
# Find min and max of sales list.
print(min(sales))
print(max(sales))
81
163