Python oct() Built in Function

The oct() function in Python converts an integer number into an octal string. Octal strings in Python are prefixed with 0o. The oct() function can also convert numbers from other bases, such as binary or hexadecimal, into octal.

Here are some examples of using oct() function in Python:

Using oct() with a decimal number

# This example converts a decimal number into an octal string
x = oct(12)
print(x)
# Output: 0o14

Using oct() with a binary number

# This example converts a binary number into an octal string
x = oct(0b1010)
print(x)
# Output: 0o12

Using oct() with a hexadecimal number

# This example converts a hexadecimal number into an octal string
x = oct(0xAF)
print(x)
# Output: 0o257

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Stock Market Predictions with LSTM in Python

Collections In Python

Python Count Occurrence Of Elements

Python One Liner Functions