Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Ints vs. floats

The decimal point is essentially important in recognizing floating-point numbers in Python. 

Look at these two numbers: 

4
4.0

You may think they are exactly the same, but Python sees them in a completely different way. 

4 is an integer number, whereas 4.0 is a floating-point number. 

The point is what makes a float. 

On the other hand, it's not only points that make a float. You can also use the letter e. 

When you want to use any numbers that are very large or very small, you can use scientific notation. 

Take, for example, the speed of light, expressed in meters per second. Written directly it would look like this: 300000000

to avoid writing out so many zeros, physics textbooks use an abbreviated form, which you have probably already seen: 3 x 10^8

It reads: three times ten to the power of eight. 

IN Python, the same effect is achieved in a slightly different way - take a look: 

3E8

The letter E (you can also use the lower-case e - it comes from the word exponent) is a concise record of the phrase times ten to the power of. 

Note: 

  • the exponent (the value after the E) has to be an integer
  • the base (the value in front of the E) may be an integer. 

Coding Floats

Let's see how this convention is used to record numbers that are very small (in 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.000000000000000000000001

When you run this literal through Python: 

Print(0.00000000000000001)

This is the result: 

1e-22

Python always chooses the more economical form of the number's presentation, and you should take this into consideration when creating literals.