What is colorsys.hls_to_rgb(h, l, s) in Python?
The colorsys.hls_to_rgb(r, g, b) function converts HLS (Hue Lightness Saturation) coordinates to RGB (Red Green Blue) coordinates.
Declaration
The colorsys module stores the definition of the hls_to_rgb() function. The colorsys module can be imported using the following code:
import colorsys
colorsys.hls_to_rgb(h, s, v)
h, l, and s can have any value between 0 and 1 inclusive.
Code
The following code snippet demonstrates the use of hls_to_rgb():
import colorsysif __name__ == '__main__':h = 0.17l = 0.82s = 0.45r, g, b = colorsys.hsv_to_rgb(h, l, s)print('HLS:-')print('h: ' + str(h) + '\nl: ' + str(l) + '\ns: ' + str(s))print('\nRGB:-')print('r: ' + str(r) + '\ng: ' + str(g) + '\nb: ' + str(b))
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved