Hexadecimal and Octal integers in python

By: Python Documentation Team Viewed: 161 times  Printer Friendly Format    


To specify an octal digit, precede the octal value with a zero, and then a lower or uppercase 'o'. For example, to set the variable 'a' to the octal value '10' (8 in decimal), type:

>>> a = 0o10
>>> a
8

Hexadecimal is just as easy. Simply precede the hexadecimal number with a zero, and then a lower or uppercase 'x'. Hexadecimal digits can be specified in lower or uppercase. For example, in the Python interpreter:

>>> a = 0xa5
>>> a
165
>>> b = 0XB2
>>> b
178



Most Viewed Articles (in Python )

Latest Articles (in Python)

Comment on this tutorial