Python Function Reference

oct

Convert an integer to octal notation.

Python 3.13
oct(x)

Parameters

xint
An integer.

Return value

A string with the 0o prefix, such as "0o10".

Examples

Octal notation

Python 3.13
print(oct(8))
0o10

File permissions

Python 3.13
print(oct(493))
0o755

Details

Octal notation is most often seen in file permissions: 0o755. A string is converted back with int("755", 8). In code, an octal number is written with the 0o prefix: 0755 is a syntax error.

See also