2.1.2.7 Python literals
Coding floats
Let's see how this convention is used to record numbers that are very small (in the sense of their absolute value, which is close to zero).
A physical constant called Planck's constant (and denoted as h), according to the textbooks, has the value of: 6.62607 x 10-34.
If you would like to use it in a program, you should write it this way:
6.62607E-34
Note: the fact that you've chosen one of the possible forms of coding float values doesn't mean that Python will present it the same way.
Python may sometimes choose different notation than you.
For example, let's say you've decided to use the following float literal:
0.0000000000000000000001
When you run this literal through Python:
print(0.0000000000000000000001)
this is the result:
1e-22
output
Python always chooses the more economical form of the number's presentation, and you should take this into consideration when creating literals.
Comments
Post a Comment