#What is the data type of the expression 4 0.5 value in python?
In the expression, 4 is an integer and 0.5 is a floating point number, so the value type of their addition is Floating point.
>>> type(4+0.5) <class 'float'>
The analysis is as follows:
The result of Python's integer operation is still an integer, and the result of floating-point operation is still a floating-point number:
1 + 2 # ==> 整数 3 1.0 + 2.0 # ==> 浮点数 3.0
But the result of the mixed operation of integer and floating-point number It becomes a floating point number:
1 + 2.0 # ==> 浮点数 3.0
Why do we need to distinguish between integer operations and floating point operations?
This is because the results of integer operations are always accurate, while the results of floating point operations are not necessarily accurate, because no matter how large the computer memory is, it cannot accurately represent infinitely recurring decimals. For example, 0.1 is replaced by The binary representation is an infinite repeating decimal.
Many python training videos, all on the python learning network, welcome to learn online!
The above is the detailed content of What is the data type of the expression 4+0.5 value in python?. For more information, please follow other related articles on the PHP Chinese website!