Python Octal Number

Python octal number represent an integer in octal numeral system, it’s 8 numbers system 0 – 7, it’s related to binary system with grouping 0 and 1.

octal became famous in the early stage because were grouping binary digits and cut the code, so instead of 80 digit you may get 20 or 25 referring to a whole word.

in python as we mentioned before octal takes integer and make it more complex, then why we need it, at some advantage stage of python programming process you will need this

Python oct Function

it’s a method takes an integer and convert it to octal system


the integer could be in binary or hexadecimal system, don’t worry it’s fine.

# integer normal number
print('oct(10) is:', oct(10))

# binary number
print('oct(0b101) is:', oct(0b101))

# hexadecimal number
print('oct(0XA) is:', oct(0XA))


Write a Comment

Your email address will not be published. Required fields are marked *