打印时添加文本颜色 - Python
Add text color while print - Python
我想在打印输出时添加文本颜色。怎么做 ?
示例:Print('Hello Everyone.')
我想要输出文本
Hello Everyone
将突出显示红色。
谢谢!
一个简单的方法是导入颜色模块,如 colorama 或 termcolor。此站点可能有用:Print Colors in Python terminal。对于您的代码,它将是:
from colorama import Fore
print(Fore.RED + 'Hello Everyone')
或
import sys
from termcolor import colored, cprint
print(colored('Hello Everyone', 'red')) # method one
cprint('Hello Everyone', 'red') # method two
试试这个。
class bcolors:
HEADER = '3[95m'
OKBLUE = '3[94m'
OKGREEN = '3[92m'
WARNING = '3[93m'
FAIL = '3[91m'
ENDC = '3[0m'
BOLD = '3[1m'
UNDERLINE = '3[4m'
print(bcolors.OKGREEN + 'Hello Everyone')
我想在打印输出时添加文本颜色。怎么做 ?
示例:Print('Hello Everyone.')
我想要输出文本
Hello Everyone
将突出显示红色。
谢谢!
一个简单的方法是导入颜色模块,如 colorama 或 termcolor。此站点可能有用:Print Colors in Python terminal。对于您的代码,它将是:
from colorama import Fore
print(Fore.RED + 'Hello Everyone')
或
import sys
from termcolor import colored, cprint
print(colored('Hello Everyone', 'red')) # method one
cprint('Hello Everyone', 'red') # method two
试试这个。
class bcolors:
HEADER = '3[95m'
OKBLUE = '3[94m'
OKGREEN = '3[92m'
WARNING = '3[93m'
FAIL = '3[91m'
ENDC = '3[0m'
BOLD = '3[1m'
UNDERLINE = '3[4m'
print(bcolors.OKGREEN + 'Hello Everyone')