Programming Tutorials

Hexadecimal and Octal integers in python

By: Python Team in Python Tutorials on 2012-04-07  

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





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Python )

Latest Articles (in Python)