Python oct() built-in function

From the Python 3 documentation

Convert an integer number to an octal string prefixed with “0o”. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.

Introduction

The oct() function converts an integer into its octal representation. The resulting string is prefixed with “0o” to indicate that it’s an octal number.

Examples

Here are a few examples of how to use oct():

# Convert integers to octal
print(oct(8))    # Output: 0o10
print(oct(10))   # Output: 0o12
print(oct(100))  # Output: 0o144
print(oct(1))    # Output: 0o1
print(oct(1000)) # Output: 0o1750

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.