Numbers



examples/numbers/numbers.py
a = 42   # decimal
h = 0xA  # 10 - hex            - staring with 0x
o = 0o11 # 9  - octal          - starting with 0o
         # 011 works in Python 2.x but Python 3.x
         # requires the o that works in
         # (recent versions of) Python 2.x
b = 0b11 # 3  - binary numbers - starting with 0b

r = 2.3

print(a)  # 42
print(h)  # 10
print(o)  #  9
print(b)  #  3
print(r)  #  2.3
In Python numbers are stored as decimals, but in the source code you can also use hexadecimal, octal, or binary notations. This is especially useful if the domain you are programming in is using those kinds of numbers. For example hardware engineers often talk in hexadecimal values. In that case you won't need to contantly translate between the form used in the current domain and decimal numbers.