# hex() function with example in Python

Python hex() function: Here, we are going to learn about the hex() function in Python with example.
Submitted by IncludeHelp, on April 03, 2019

## Python hex() function

hex() function is a library function in Python, it is used to get the hexadecimal value of a given number, it accepts a number and returns a hexadecimal value (string format). It can be used to convert an integer number to a hexadecimal value.

Syntax:

```    hex(number)
```

Parameter(s):number – a valid number to be converted into hexadecimal.

Return value: str – it returns hexadecimal value in string format of given number.

Example:

```    Input:
num = 12345

print("hex value of ", num, " is = ", hex(num))

Output:
hex value of  12345  is =  0x3039
```

Python code to get the hexadecimal value of a given number

```# python code to demonstrate example
# of hex() function

num = 0
print("hex value of ", num, " is = ", hex(num))

num = 10
print("hex value of ", num, " is = ", hex(num))

num = 12345
print("hex value of ", num, " is = ", hex(num))

num = -12345
print("hex value of ", num, " is = ", hex(num))
```

Output

```hex value of  0  is =  0x0
hex value of  10  is =  0xa
hex value of  12345  is =  0x3039
hex value of  -12345  is =  -0x3039
```

Preparation