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

Integers: octal and hexadecimal numbers

There are two additional conventions in Python that are unknown to the world of mathematics. The first allows us to use numbers in an octal representation. 

If an integer number is preceded by an 0o or 0O prefix (zero-o), it will be treated as an octal value. This means that the number must contain digits taken from the [0..7] range only. 

0o123 is an octal number with a (decimal) value equal to 83.

The print() function does this conversion automatically. Try this: 

print(0o123)

The second convention allows us to use hexadecimal number. Such numbers should be preceded by the prefix 0x or 0X (zero-x)

0x123 is a hexadecimal number with a (decimal) value equal to 291. The print() function can manage these values too. Try this: 

print(0x123)

 

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 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.