Floats
Now it's time to talk about another type, which is designed to represent and to store the numbers that (as a mathematician would say) have a non-empty decimal fraction.
They are the numbers that have (or may have) a fractional part after the decimal point, and although such a definition is very poor, it's certainly sufficient for what we wish to discuss.
Whenever we use a term like two and a half or minus zero point four, we think of numbers which the computer considers floating-point numbers:
2.5
-0.4
Note: two and a half looks normal when you write it in a program, although if your native language prefers to use a comma instead of a point in the number, you should ensure that your number doesn't contain any commas at all.
Python will not accept that, or (in very rare but possible cases) may misunderstand your intentions, as the comma itself has it's own reserved meaning in Python.
If you want to use just a value of two and a half, you should write it as shown above. Note once again - there is a point between 2 and 5 - not a comma.
As you can probably imagine, the value of zero point four could be written in Python as:
0.4
But don't forget this simple rule - you can omit zero when it is the only digit in front of or after the decimal point.
In essence, you can write the value 0.4 as:
.4
This will change neither its type nor its value.
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: