Back to Resources

Tutorial · 8 min read · sample article

Your first Python script, explained line by line

A tiny program that reads a list and summarizes it, with every line explained.

We will write a script that takes a list of numbers and prints the total and the average.

The idea

Store the numbers in a list, add them up with sum(), and divide by len() to get the average.