number :input integer number
Return the Octal number as string.
print(oct(my_num)) # 0o33
This will generate TypeError
TypeError: 'float' object cannot be interpreted as an integer
Binary to Octal
In above code the input binary number is equivalent to integer 27.
print(oct(0b11011)) # 0o33
You can use bin() to get the binary output
print("Binary Number : ", bin(27)) # Binary Number : 0b11011
Hex to Octal
In above code the input Hex number is equivalent to integer 27
You can use hex() to get the Hex output
print(oct(0x1b)) # 0o33
In our octal output,
print("Hex Number : ", hex(27)) # Hex Number : 0x1b
0o is always prefixed. As the output is a string we can remove it like this
Without using oct() and by using format()
print(my_oct[2:]) # 33
All Built in Functions in Python
print(format(my_num,'o')) # 33
max() Bitwise operators
Subscribe to our YouTube Channel here
This article is written by plus2net.com team.