本文介绍了如何使用 Python 3 打印彩色输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的打印语句:
I have a simple print statement:
print('hello friends')
我希望终端中的输出为蓝色.我怎样才能用 Python3 做到这一点?
I would like the output to be blue in the terminal. How can I accomplish this with Python3?
推荐答案
It is very simple with colorama, just do this:
import colorama
from colorama import Fore, Style
print(Fore.BLUE + "Hello World")
And here is the running result in Python3 REPL:
And call this to reset the color settings:
print(Style.RESET_ALL)
To avoid printing an empty line write this:
print(f"{Fore.BLUE}Hello World{Style.RESET_ALL}")
这篇关于如何使用 Python 3 打印彩色输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!