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.
Decimal | Octal | Decimal | Octal |
---|---|---|---|
1 | 1 | 8 | 10 |
2 | 2 | 9 | 11 |
3 | 3 | 16 | 20 |
4 | 4 | 50 | 62 |
5 | 5 | 100 | 144 |
6 | 6 | 500 | 764 |
7 | 7 | 1000 | 1750 |
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