Caffeinated Coder
Book an appointment
Lesson 10 · Collections and functions

Functions

A function is a named group of steps you write once and run whenever you need it. Step through a seven-line program, avg.py, that defines average(nums) and calls it twice: watch def store the function, each call hand in a list and get its own call frame, the body work out the answer, and return send one value back to the line that asked. Finish with the most common slip: forget return and you get None.

12 min9 steps5 questionsBeginner
Fig 10 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.