Built-in Functions and Types
oct()
Format an integer as base-8 text with the prefix 0o. Negative inputs place the minus sign before the prefix rather than emitting a fixed-width two’s-complement bit pattern. Objects implementing __index__() are accepted; floats are not implicitly truncated. Use format() if a prefix-free or width-controlled representation is needed.
Formal Syntax & Structure
python syntaxpython
oct(integer, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| integer | int or object supporting __index__ | Integer-like value; positional only. |
Return Value
str
A base-8 representation with 0o and an optional leading minus sign.
Working Example
Example Snippetpython
print(oct(73))print(oct(-9))