Python Tutorial Python Advanced Python References Python Libraries

Python oct() Function



The Python oct() function is used to convert a specified number (positive or negative integers only) into octal numeral system. It returns a octal string which always starts with 0o followed by octal value of the specified number.

Syntax

oct(number)

Parameters

number Required. specify a positive or negative integer.

The table below shows decimal numbers converted into octal numbers.

DecimalOctalDecimalOctal
11810
22911
331620
445062
55100144
66500764
7710001750

Example:

The example below shows how to convert decimal number into octal number in Python.

MyNumber = oct(100)
print(MyNumber)

MyNumber = oct(1000)
print(MyNumber)

The output of the above code will be:

0o144
0o1750

❮ Python Built-in Functions