In Python, you can define the type of a variable. The built-in function is used for this. type
:
name = "Ivan"
print(type(name)) # <class 'str'>
n = 5
print(type(n)) # <class 'int'>
r = 5.0
print(type(r)) # <class 'float'>
The value
5.0 is a number represented as a decimal fraction (has an integer and fractional part). In computer science, such numbers are called
real
A real number is a number in which there is an integer and fractional parts. The integer and fractional parts are separated by
a dot
Even if the fractional part of the number is zero, as in the
r variable in the example, the translator will still create a real variable in memory. The point, as it were, is a signal for the translator that it is necessary to create a real variable.
Very large and very small numbers are written using a "floating point" (in the so-called scientific format).
In a scientific format, the number is represented in the form of a mantissa (a significant part of the number) and order. When recording, the mantissa and the order are separated from each other by the letter e (denotes 10 to some extent).
For example, you can save the value of the electron charge in a variable (
\(1,60217662 \times 10^{-19}\) Cl), writing as follows
El = 1.60217662e-19 #for a positive order, the + sign can be omitted
Almost all real numbers cannot be stored in computer memory with perfect accuracy, since a limited number of bits are allocated for their storage. Therefore, in calculations with real numbers, errors associated with inaccuracy of the representation are accumulated. Moreover, the less space is allocated, the greater this error will be.