w3resource

Python: oct() function

oct() function

The oct() function is used to convert an integer number to an octal string.

Octal strings in Python are prefixed with 0o.

Version:

(Python 3.2.5)

Syntax:

oct(x)

Parameter:

Name Description Required /
Optional
x An integer. Required

Return value:

Returns an octal string from the given integer number.

Example: Python oct() function

# decimal number
print('oct(11) is:', oct(11))

# binary number
print('oct(0b110) is:', oct(0b110))

# hexadecimal number
print('oct(0XB) is:', oct(0XB))

Output:

oct(11) is: 0o13
oct(0b110) is: 0o6
oct(0XB) is: 0o13

Pictorial Presentation:

Python: Built-in-function - oct() function

Pictorial Presentation:

Python: Built-in-function - oct() function

Pictorial Presentation:

Python: Built-in-function - oct() function

Python Code Editor:

Previous: object()
Next: open()

Test your Python skills with w3resource's quiz



Follow us on Facebook and Twitter for latest update.