\033[1;31;40m # 1是显示方式(可选),31是字体颜色,40m 是字体背景颜色;
\033[0m # 恢复终端默认颜色,即取消颜色设置;
# cat color.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 字体颜色
print "=====字体颜色======"
for i in range(31, 38):
print "\033[%s;40mHello world!\033[0m" %i
# 背景颜色
print "=====背景颜色======"
for i in range(41, 48):
print "\033[47;%smHello world!\033[0m" %i
# 显示方式
print "=====显示方式======"
for i in range(1, 9):
print "\033[%s;31;40mHello world!\033[0m" %i
# python color.py