= 2
x print(type(x))
print(x)
<class 'int'>
2
Congratulations, you are already probably familiar with numbers!
In Python, there are two kinds of numbers: integers and floats. Integers are whole numbers without a decimal component, while floats have decimal component (even if it is X.0):
= 2
x print(type(x))
print(x)
<class 'int'>
2
= 4.5
x print(type(x))
print(x)
<class 'float'>
4.5
= 2 / 3
x print(type(x))
print(x)
<class 'float'>
0.6666666666666666
= 2.0
x print(type(x))
print(x)
<class 'float'>
2.0
When dealing with large numbers, it may be helpful to visually separate using underscores. These variants are treated as if the underscores were not there:
= 120_000
x print(type(x))
print(x)
<class 'int'>
120000
= 120_000.0
x print(type(x))
print(x)
<class 'float'>
120000.0
It is no surprise, we can use Python as a glorified calculator, to perform arithmetic operations:
print(2 + 10)
print(2 - 10)
print(2 * 10)
print(2 / 10)
12
-8
20
0.2
It is possible to round numbers using the round
function:
print(round(6.675555, 0))
print(round(6.675555, 1))
print(round(6.675555, 2))
print(round(6.675555, 3))
print(round(6.675555, 4))
print(round(6.675555, 5))
7.0
6.7
6.68
6.676
6.6756
6.67556