# How to convert HEX to RGB in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about How to convert HEX to RGB in Python. so without wasting time lets learn about of this.

## How to convert HEX to RGB in Python

1. convert HEX to RGB in Python

to convert HEX to RGB in Python just Use PIL.By using PIl you can convert HEX to RGB in python. Lets learn about of this by given below example: `from PIL import ImageColor hex = input('Enter HEX value: ') ImageColor.getcolor(hex, "RGB")` Output : `Enter HEX value: 7800ff RGB value = (120, 0, 255)`

2. How to convert HEX to RGB in Python

to convert HEX to RGB in Python just Use tuple()function.By using tuple()function you can convert HEX to RGB in python. Lets learn about of this by given below example:
`hex = input('Enter HEX value: ').lstrip('#') print('RGB value =', tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)))` Output : `Enter HEX value: 7800ff RGB value = (120, 0, 255)`

3. hex to rgb

To convert HEX to RGB in Python just Use tuple()function.By using tuple()function you can convert HEX to RGB in python. Lets learn about of this by given below example:
`hex = input('Enter HEX value: ').lstrip('#') print('RGB value =', tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)))` Output : `Enter HEX value: 7800ff RGB value = (120, 0, 255)`

## Method 1: Use PIL

By using PIl you can convert HEX to RGB. Lets learn about of this by given below example:

``````from PIL import ImageColor
hex = input('Enter HEX value: ')
ImageColor.getcolor(hex, "RGB")``````

Output :

``````Enter HEX value: 7800ff
RGB value = (120, 0, 255)``````

## Method 2: Use tuple()function

By using tuple()function you can convert HEX to RGB. Lets learn about of this by given below example:

``````hex = input('Enter HEX value: ').lstrip('#')
print('RGB value =', tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)))``````

Output :

``````Enter HEX value: 7800ff
RGB value = (120, 0, 255)``````

## Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?