The Python oct() function
Description
oct() The function converts an integer to an octal string.
- In Python 2.x, octal numbers are represented with a leading 0.
- In Python 3.x, octal numbers are represented with a leading 0o.
Syntax
oct syntax:
oct(x)
Parameter Description:
- x -- an integer.
Return Value
Returns an octal string.
Example
The following examples demonstrate how to use oct:
Example (Python 2.0+)
oct
(
10
)
'012'
oct
(
20
)
'024'
oct
(
15
)
'017'
Example (Python 3.0+)
oct
(
10
)
'0o12'
oct
(
20
)
'0o24'
oct
(
15
)
'0o17'
Python built-in function