DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1

A floating point number is just a whole number with a
decimal point. When you divide in Python, you often get
a remainder that is displayed as a floating point number,
as in this example:


>>> 10 / 7
1.4285714285714286

If you just want to see whole numbers, you can use
integer division and lop off the remainder, as shown
here:


>>> 10 // 7
1

Likewise, if you are only interested in the remainder, you
can have modulus division show you what is left over:


>>> 10 % 7
3

You have the option to use other base systems instead of
just the default base 10. You have three choices in
addition to base 10: binary (base 2), octal (base 8), and
hex (base 16). You need to use prefixes before integers in
order for Python to understand that you are using a
different base:


0b or 0B for binary
0o or 0O for octal
0x or 0X for hex

From Python’s perspective, these are still just integers,
and if you type any of them into the interpreter, it will
return the decimal value by default, as shown in this
example:

Free download pdf