6.2. Naming Procedures and Functions¶
We’ve already seen how we can use names to represent numbers (both integers like
-325 and decimal numbers like
-322.9392), strings (like
"Hi There"), turtles, and images. When we do calculations using the names, the computer will look up the value for each name, and then use the value in the calculation. We can also name a sequence of statements and then ask the computer to run that sequence whenever we use that name. This is similar to asking someone to do a dance that they know, like the Macarena or Salsa. Once you know the dance you can do the steps.
In programming there are two different terms used for a named sequence of statements: procedure and function. A procedure accomplishes some task or makes something happen, but doesn’t return anything. A function returns a result. Many procedures and functions are built into Python. The function
abs returns the absolute value of its input. The function
int takes a decimal number as input and returns just the integer part.
Discuss topics in this section with classmates.