Boston Python Workshop 3/Data types
Numbers: integers and floats
Addition
>>> 2 + 2 4
Subtraction
>>> 0 - 2 -2
Multiplication
>>> 2 * 3 6
Division
>>> 4 / 2 2 >>> 1 / 2 0
Integer divison produces an integer. You need a number that knows about the decimal point to get a decimal out of division:
>>> 1.0 / 2 0.5 >>> float(1) / 2 0.5
Remainder
>>> 4 % 2 0 >>> 4 % 3 1
Types
>>> type(1) <type 'int'> >>> type(1.0) <type 'float'>