如何以彩色打印到控制台? [英] How to print to console in color?

查看:55
本文介绍了如何以彩色打印到控制台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用python打印进行彩色打印.例如

How to print in color using python print. For example

print('This should be red')
print('This should be green')

现在一切都是黑底白字.如果有帮助,我使用 ubuntu.

Now everything is white text on black background. I use ubuntu, if it helps.

推荐答案

像这样定义颜色:

W  = '\033[0m'  # white (normal)
R  = '\033[31m' # red
G  = '\033[32m' # green
O  = '\033[33m' # orange
B  = '\033[34m' # blue
P  = '\033[35m' # purple

print(R+"hello how are you"+W)

演示:

在此处查看所有颜色代码:颜色代码

see all color codes here:Color Codes

这篇关于如何以彩色打印到控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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