Python's Colorama module can display different colors and backgrounds of fonts across multiple terminals. You only need to import the colorama module, and you don't need to specify the color like linux every time;
Official reference: https://pypi.org/project/colorama/
1. Install the colorama module
win
python -m pip install colorama
linux
pip install colorama
2. Common format constants
Fore is for font color, Back is for font background color, Style is for font format
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Style: DIM, NORMAL, BRIGHT, RESET_ALL
Note below that the colors RED and GREEN need to be capitalized. First specify whether the color and style are for the font or the font background, and then add the color
from colorama import Fore, Back, Style print(Fore.RED + 'some red text') print(Back.GREEN + 'and with a green background') print(Style.DIM + 'and in dim text') print(Style.RESET_ALL) print('back to normal now')
Init keyword arguments:
init() accepts some **kwargs to override the default behavior,
autoreset is to automatically restore to the default color
init(autoreset = False):
Autoreset is set to True, the last line of output has returned to the default font color and background
from colorama import init,Fore init(autoreset=True) print (Fore.RED + "welcome to python !!") print ("automatically back to default color again")