Python oct() Function
Converts an integer to octal, a base 8 number.
Syntax
Python
Copy Code
oct(number)
Parameters
Parameter | Description |
---|---|
number |
Required. The value to convert |
Example
Python
Copy Code
squawk = 7421 print(oct(squawk))
Output
0o16375
Notes
If the object is not an int
, is has to define the __index__()
function and
return an integer.
Example
Python
Copy Code
class Transponder(): squawk = 7421 def __index__(self): return self.squawk print(oct(Transponder()))Output:
0o16375
Who uses Octal?
Octal is often used in aviation — transponders in aircraft transmit a code, expressed as a four-octal-digit number, when interrogated by ground radar. This code is used to distinguish different aircraft on the radar screen.