Chapter 3 – The Interactive Shell 27
Figure 3-1. Type 2+2 into the shell.
2 + 2 isn’t a program by itself, it’s just a single instruction (we’re just learning the basics right
now). The + sign tells the computer to add the numbers 2 and 2. To subtract numbers use the –
sign. To multiply numbers use an asterisk (*) and to divide numbers use /.
Table 3 - 1: The various math operators in Python.
Operator Operation
+ addition
- subtraction
- multiplication
/ division
When used in this way, +, -, *, and / are called operators because they tell the computer to
perform an operation on the numbers surrounding them. The 2 s (or any other number) are called
values.
Integers and Floating Point Values
In programming whole numbers like 4 , 0 , and 99 are called integers. Numbers with fractions or
decimal points (like 3.5 and 42.1 and 5.0) are floating point numbers. In Python, the
number 5 is an integer, but if we wrote it as 5.0 it would be a floating point number
Expressions
Try typing some of these math problems into the shell, pressing Enter key after each one:
2+2+2+2+2
8*6
10 - 5+6
2 + 2