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:
Pictorial Presentation:
Pictorial Presentation:
Python Code Editor:
Previous: object()
Next: open()
Test your Python skills with w3resource's quiz
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python/built-in-function/oct.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics