# Implementation of oct() function in Python

**oct() function in Python: **oct() function is an important function in Python . It transforms any data type into the octal form. If anyone wants to convert any data from any format to octal form then it can be done easily with the help of oct() function.

**Format:- **oct(data), data is in int format.

**Parameters:- **inside the oct function we have to only pass the integer data.

**Diagrammatic representation of oct function:-**

## Implementation of oct function in Python

**Decimal to octal:-**

#decimal to octal a=int(input()) b=oct(a) print("the number " + str(a) +" in octal form is "+ str(b))

Here, we take a decimal number as input and print that number in the octal form.

**Binary to octal:-**

# Binary to octal c=int(input(),2) d=oct(c) print("the number " + str(c) +" in octal form is "+ str(d))

Here, we take a binary number as input and print that number in the octal form.

**Hexadecimal to octal:-**

#Hexadecimal to octal e=int(input(),16) f=oct(e) print("the number " + str(e) +" in octal form is "+ str(f))

Here, we take a hexadecimal number as input and print that number in octal form.

### Output:-

10 the number 10 in octal form is 0o12 11010011 the number 211 in octal form is 0o323 FFFF the number 65535 in octal form is 0o177777

Here first we take a decimal number 10 as input and print its octal form.

Next, we take a binary number 11010011 as input and print its octal form.

After that, we take a hexadecimal number FFFF as input and print its octal form.

## Leave a Reply