首页 > 代码库 > python 输出彩色文字

python 输出彩色文字

直接上代码,写了一个选择双色球号码的小东西来显示字体颜色。

pip install clint

将以下代码复制,执行变可看到python在list与string转化,以及彩色文字的输出有多么方便了。

#!/usr/bin/python
import random
import string
from clint.textui import colored
red = []
blue = []
red_res=[]
blue_res=[]
for r in range(1,34):
    red.append(r)
for b in range(1,17):
    blue.append(b)
for i in range(6):
    a = random.choice(red)
    red_res.append(str(a))
    red.remove(a)
print colored.green("red ball are:")+colored.red(",".join(sorted(red_res))),colored.green("blue ball is:")+colored.blue(random.choice(blue))

本文出自 “技术为王” 博客,请务必保留此出处http://wangzhenyu.blog.51cto.com/2996939/1591106

python 输出彩色文字