本文介绍了如何使用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")

这是Python3 REPL中的运行结果:

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打印彩色输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:30
查看更多