在Python中将RGB颜色元组转换为六位数代码 [英] Converting a RGB color tuple to a six digit code, in Python

查看:1016
本文介绍了在Python中将RGB颜色元组转换为六位数代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要转换(0,128,64)这样的#008040。我不知道什么叫做后者,使搜索困难。

I need to convert (0, 128, 64) to something like this #008040. I'm not sure what to call the latter, making searching difficult.

推荐答案

使用格式运算符

>>> '#%02x%02x%02x' % (0, 128, 64)
'#008040'


$ b b

注意,它不会检查边界...

Note that it won't check bounds...

>>> '#%02x%02x%02x' % (0, -1, 9999)
'#00-1270f'

这篇关于在Python中将RGB颜色元组转换为六位数代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆