在 Python 终端中打印颜色
在终端中,如果你想让一些文本以彩色模式显示,可以使用 python 编程中的多种方法来实现。
使用 Python 模块
1.termcolor 模块:此模块用于为终端中的输出设置 ANSII 颜色格式。
import sys
from termcolor import colored, cprint
text1 = colored('Hello, Tutorialspoint!', 'blue', attrs=['reverse', 'blink'])
print(text1)
cprint('Hello, Python!', 'blue', 'on_white')
print_red_on_blue = lambda x: cprint(x, 'red', 'on_blue')
print_red_on_blue('Hello, from Data Science!')
print_red_on_blue('Hello, Python!')
for i in range(10):
cprint(i, 'green', end=' ')
cprint("Attention!", 'blue', attrs=['bold'], file=sys.stderr)结果

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP