Floats and integers
Floats and integers represent rational numbers with and without a decimal part, respectively. Those types are quite intuitive to use, as they can be added, subtracted, multiplied, divided, and more. Let's take a look at the following example. First, we assign two variables:
A = 6
B = 5
Now, let's go over some possible operations:
>>> A + B
11
>>> A - B
1
>>> A / B
1.2
>>> A * B
30
You can also raise numbers to a power by using double asterisks:
>>> 2**3
8
>>> 3**2
9
You might have noticed that the division of two integers will result in a float. This happens even if the remainder is zero:
>>> 10 / 2
5.0
If you need to keep the integer division result as an integer (rounded, if needed), then use a double slash instead; this operation has significantly higher performance. However, if any of the two values is a float, then it will keep the result as a float, although rounded. The following code shows this:
>>> 9 // 4
3
>>> 10.0 // 4
2.0
Finally, you can also get the remainder (or modulus) by using a percentage sign:
>>> 10 % 3
1