Python oct() function
Python oct() function
The oct() function in Python converts an integer number to an octal string prefixed with “0o”.
Syntax
oct(x)
Parameter
x: This parameter represents an Integer Number
Return
This function returns an octal string.
Example 1
# Python program explaining # the oct() function num= 128 oct_val = oct(num) print("The octal value for",num,"is",oct_val)
Output
The octal value for 128 is 0o200
Example 2
# Python program explaining # the oct() function print("The octal representation of the ascii value 'r' is " + oct(ord('r'))) # For 23, Hexadecimal is 0x17 print("The octal representation of the binary: " + oct(0x17))
Output
The octal representation of the ascii value 'r' is 0o162 The octal representation of the binary: 0o27