Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

oct()

Formats an integer as a base-eight string with an octal prefix.

Version: Python 3.14; repository image, production runtime not attested

Syntax

oct(integer, /)

Formats an integer as a base-eight string with an octal prefix.

The minus sign precedes the prefix on a negative input; a positive permission mask can be displayed without changing its integer value.

Three octal digits 755 represent 7×64+5×8+5 = 493, useful when displaying a permission mask. The prefix identifies base eight. With −8 the minus sign comes before 0o10; converting the result with base eight recovers the integer.

assert oct(493) == "0o755" and oct(-8) == "-0o10"
assert int(oct(493), 8) == 493

Examples

print(oct(493))
print(oct(-8))

Result

0o755
-0o10

Three octal digits 755 represent 7×64+5×8+5 = 493, useful when displaying a permission mask. The prefix identifies base eight. With −8 the minus sign comes before 0o10; converting the result with base eight recovers the integer.

Sources