Friday, September 22, 2023
HomeSoftware EngineeringThe best way to Convert HEX to RBG in Python

The best way to Convert HEX to RBG in Python


If you must convert HEX (Hexadecimal) to RGB (Purple-Inexperienced-Blue) in your Python code, then you are able to do the next:

Possibility 1 – Utilizing the PIL library

from PIL import ImageColor
hex = enter('Enter HEX worth: ')
ImageColor.getcolor(hex, "RGB")

Possibility 2 – Utilizing a customized resolution

hex = enter('Enter HEX worth: ').lstrip('#')
print('RGB worth =', tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)))
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments