# How to convert octal to hexadecimal in python

In this tutorial, we will learn how to convert octal to hexadecimal in python with some cool and easy examples. In many situations, you might have to come up with this type of requirements.

We hope you will get help from this easy tutorial.

## Convert octal to hexadecimal in Python

Here in python the hex function can convert any string or number into the hexadecimal, or return 0 if no arguments are given then it shows* “TypeError: hex() takes exactly one argument (0 given)”*.

Thus we can easily use the built-in function without taking extra effort to make this essential conversion.

Hexadecimal can only take exactly one argument is you give more than one number it shows Type error

The hexadecimal can only support hexadecimal representation.

hex(number, /)

Return the hexadecimal representation of an integer.

In this below code we explain 3 tricks to convert octal to hexadecimal in python so that you can choose the efficient way as per your priorities.

This octal to hexadecimal conversion tricks will simplify your burden work.

**Example:-** value= int(“octal value”,8)

x=int(“0o12”,8)

>>> hex(x)

‘0xa’(or)

x=0o12

>>> hex(x)

‘0xa’

Compare the above example with give sample code.

x= hex(0o12) print("your hexdecimal value is:" x)

x=int("0o12",8) print(hex(x))

x=0o12 print(hex(x))

**OUTPUT 1:**

your octal value is : 0xa

**OUTPUT 2:**

oxa

**3rd output:**

oxa

You may also read:

It’s simple but efficient for intermediate levels

Explained well,helped me alot will be looking forward for more of ur work

Thank you☺

Good work satish …

Thanks satish