The oct() function in Python is a built-in function used to convert an integer number into its octal representation. The octal number is returned as a string prefixed with 0o, which indicates that the number is in base-8 (octal system).
The octal number system uses eight digits: 0–7. It is sometimes used in computing, especially in file permissions in operating systems and certain low-level programming tasks.
oct(number)
0o, which indicates octal notation.print(oct(10))
Output
0o12
Explanation
0o to indicate octal format.print(oct(25))
Output
0o31
Explanation
0o PrefixIf only the octal digits are needed, the prefix can be removed.
num = 25
oct_value = oct(num)
print(oct_value[2:])
Output
31
Explanation
oct_value[2:] removes the first two characters (0o) from the result.print(oct(-12))
Output
-0o14
Explanation
number = 64
octal_value = oct(number)
print("Decimal:", number)
print("Octal:", octal_value)
Output
Decimal: 64
Octal: 0o100
Explanation
oct() is a built-in Python function used to convert an integer into its octal representation.0o, which represents octal format.