50 Chapter 3
get the remainder, we use the modulo operator, which we repre-
sent in Python with the % symbol. Don’t confuse % with percent—in
Python, you’ll write percentages as decimals (5% becomes 0.05),
and the % operator is always the modulus, or remainder result-
ing from integer division. To get the remainder of long division
in Python, type 10 % 4 (gives a remainder of 2 ) or 7 % 4 (equals a
remainder of 3 ). Figure 3-10 shows the result of several math oper-
ations, including integer division and remainders using the // and %
operators.
Figure 3-10: Python tackles your math homework.
As we continue through the book, we’ll be using the % operator
in programs like our spiral drawings to keep numbers fixed in a
certain range.
What You Learned
In this chapter, you’ve seen how to store different types of infor-
mation, including numbers, lists, and strings, in variables. You
learned the rules for naming variables in Python (letters, under-
scores, numbers; case sensitive; no spaces) and how to assign
values to them with the equal sign operator (my_name = "Alex" or
my_age = 5).
You also learned about integers (whole numbers) and floating-
point numbers (decimal values). You learned about the various
math operators in Python and how they differ from the symbols
you might use in a math textbook. You saw how to use strings of