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](https://www.w3resource.com/w3r_images/built-in-function-oct-function-image-1.png)
Pictorial Presentation:
![Python: Built-in-function - oct() function](https://www.w3resource.com/w3r_images/built-in-function-oct-function-image-2.png)
Pictorial Presentation:
![Python: Built-in-function - oct() function](https://www.w3resource.com/w3r_images/built-in-function-oct-function-image-3.png)
Python Code Editor:
Previous: object()
Next: open()
Test your Python skills with w3resource's quiz
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics