Python for Data: First Steps
Turn a list of numbers into real answers
- store data as a list of numbers,
- use
sum()andlen()to get a total and a count, - calculate an average, and find the
max()andmin().
1. Numbers in a list are "data"
You already know a list can hold many values inside square brackets. When those values are numbers we can measure, we call the whole collection data. It could be test scores, daily temperatures, the heights of your friends, or points in a game.
Here is a small list of quiz scores. We can print the whole list, and use len() to count how many scores there are:
scores = [8, 5, 10, 7]
print(scores)
print(len(scores))
Expected output:
[8, 5, 10, 7]
4
len(scores) does not add the numbers — it counts the items. There are four scores, so it prints 4.
2. Data goes in, answers come out
Working with data follows a friendly pattern: your numbers go in, Python's tools process them, and useful answers come out. Think of it like a juicer: you put in fruit, turn the handle, and out comes juice.
The three little tools we turn the handle with are sum(), len(), max(), and min(). Let us meet them one by one.