根据您计划如何使用这些值,您有很多选择:
colorString = "#920310"
colorList = [0x93, 0x03, 0x10]
colorTuple = (0x93, 0x03, 0x10)
colorDict = {
"R" : 0x93,
"G" : 0x03,
"B" : 0x10,
}
或者,如果您打算有几个操作来处理您的颜色,比如转换为不同的格式,您可以定义一个 Color 类:
class Color(object):
def __init__(self, r, g, b):
self._color = (r,g,b)
def get_tuple(self):
return self._color
def get_str(self):
return "#%02X%02X%02X" % self._color
def __str__(self):
return self.get_str()
def get_YUV(self):
# ...
示例用法:
>>> a = Color(0x93, 0x03, 0xAA) # set using hex
>>> print a
#9303AA
>>> b = Color(12, 123, 3) # set using int
>>> print b
#0C7B03