python颜色随机生成器
1. 代码:
def random_color(number=number):
color = []
intnum = [str(x) for x in np.arange(10)]
alphabet = [chr(x) for x in (np.arange(6) + ord('A'))]
colorArr = np.hstack((intnum, alphabet))
for j in range(number):
color_single = '#'
for i in range(6):
index = np.random.randint(len(colorArr))
color_single += colorArr[index]
color.append(color_single)
return color
del color, intnum, alphabet, colorArr, j, i, color_single, index, number
color = random_color(number=6)
2. 小记:
- 字符转数字
ord('a')
97
数字转字符 chr(71)
‘G’ - []与()的区别
(np.arange(6) + ord('A'))
Out[158]: array([65, 66, 67, 68, 69, 70])
type((np.arange(6) + ord('A')))
Out[166]: numpy.ndarray
[np.arange(6) + ord('A')]
Out[159]: [array([65, 66, 67, 68, 69, 70])]
type([np.arange(6) + ord('A')])
Out[165]: list