June 2017
Beginner
352 pages
8h 39m
English
We've already seen Python integers in action quite a lot. Python integers are signed and have, for all practical purposes, unlimited precision. This means that there is no pre-defined limit to the magnitude of the values they can hold.
Integer literals in Python are typically specified in decimal:
>>> 1010
They may also be specified in binary with a 0b prefix:
>>> 0b102
There may also be a octal, with a 0o prefix:
>>> 0o108
If its a hexadecimal we use the 0x prefix:
>>> 0x1016
We can also construct integers by a call to the int constructor which can convert from other numeric types, such as floats, to integers:
>>> int(3.5)3
Note that, when using the int constructor, the rounding is always towards zero:
>>> int(-3.5)-3>>> int(3.5)3
Read now
Unlock full access