直接上代碼,寫了一個選擇雙色球號碼的小東西來顯示字體顏色。python
pip install clint
將如下代碼複製,執行變可看到python在list與string轉化,以及彩色文字的輸出有多麼方便了。bash
#!/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))