Numbers
In Python we mostly deal with two types of numbers: integers and floating-point numbers.
Integers
Integers are whole numbers, such as 1
, 2
, 3
, etc. Integers can be positive or negative.
Python supports basic arithmetic operations on integers, such as addition (+
), subtraction (-
), multiplication (*
), and division (/
).
Tihs is a simple example of using integer operations in Python:
print(2 + 3)
print(2 - 3)
print(2 * 3)
print(3 / 2)
which will print:
5
-1
6
1.5
Note that the division operator (/
) always returns a floating-point number, even if the result is a whole number.
Few more useful operations on numbers are the exponentiation operator (**
), the modulo operator (%
), and the floor division operator (//
).
print(2 ** 3)
print(13 % 5)
print(10 // 4)
with output:
8
3
2
Floating-Point Numbers
Any number with a decimal point is a floating-point number. Python supports the same basic arithmetic operations on floating-point numbers as it does on integers.
As an exercise, try to practice operations on floating-point numbers by modifying the examples above.