Python oct() Function
Description
oct()The function converts an integer into an octal string.
- In Python 2.x, octal is represented with0as a prefix.
- In Python 3.x, octal is represented with0oas a prefix.
Syntax
oct syntax:
oct(x)
Parameter description:
- x -- integer.
Return Value
Returns an octal string.
Example
The following example demonstrates the usage of oct:
Example (Python 2.0+)
>>> oct(10)
'012'
>>> oct(20)
'024'
>>> oct(15)
'017'
'012'
>>> oct(20)
'024'
>>> oct(15)
'017'
Example (Python 3.0+)
>>> oct(10)
'0o12'
>>> oct(20)
'0o24'
>>> oct(15)
'0o17'
'0o12'
>>> oct(20)
'0o24'
>>> oct(15)
'0o17'
Python Built-in Functions