Numbers
examples/numbers/numbers.py
a = 42 # decimal h = 0xA3C # 2620 - hex - staring with 0x o = 0o171 # 121 - octal - starting with 0o # 011 works in Python 2.x but not in Python 3.x # requires the o that works in # (recent versions of) Python 2.x b = 0b101 # 5 - binary numbers - starting with 0b r = 2.3 print(a) # 42 print(h) # 2620 print(o) # 121 print(b) # 5 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 constantly translate between the form used in the current domain and decimal numbers.