Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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 below table 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

5