001 Python-Numbers-Integers-and-Floats
001 Python-Numbers-Integers-and-Floats
With this section, now, we are starting to learn Python. First of all, we need to learn data types and data structures to
solidify our Python knowledge.
Let's start with our Python journey by learning the numbers in Python.
Integers
Integers are like whole numbers, but they also include negative numbers ... In integers no fractions allowed!
So, integers can be negative {-1, -2,-3, -4, -5, ... }, zero {0} and positive {1, 2, 3, 4, 5, ... }
Floating-point, as the name implies, are numbers that contain decimal points that can float left or right.
In programming, floating-point is used to represent fractions. Numbers such as 1/2, 3/7, -100/3 can be represented in
floating-point as 0.5, 0.42857, -33.33.
Often the keyword float is used to declare a variable that stores floating-point numbers.
Addition (+)
Subtraction (-)
Multiplication (*)
Division (/)
These operations are commonly called arithmetic operations. Arithmetic is the oldest and most elementary branch of
mathematics. In this lesson we will briefly explain basic math operations. Keep in mind that, even though the operations
and the examples shown here are pretty simple, they provide the basis for even the most complex operations used in
mathematics.
Out[2]: 7
In [3]: #Substraction
2 - 5
Out[3]: -3
In [4]: #Multiplication
2 * 11
Out[4]: 22
In [5]: #Division
6 / 3
Out[5]: 2.0
So far, we have learned our basic math operations. But the last operation, the division may have confused in your mind.
6 is an integer, 3 is an integer too. So why the result is a float? I think it would be much better to see them in the
Mathematical Operators section.
In [7]: 3 + 5 + 9 - 4 * 3
Out[7]: 5