Skip to content
This repository was archived by the owner on May 7, 2023. It is now read-only.

Files

Latest commit

 

History

History
21 lines (17 loc) · 541 Bytes

hex-to-rgb.md

File metadata and controls

21 lines (17 loc) · 541 Bytes
title type tags cover dateModified
Hex to RGB
snippet
string
math
sleepy-cat
2020-09-15 16:13:06 +0300

Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components.

  • Use a list comprehension in combination with int() and list slice notation to get the RGB components from the hexadecimal string.
  • Use tuple() to convert the resulting list to a tuple.
def hex_to_rgb(hex):
  return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
hex_to_rgb('FFA501') # (255, 165, 1)