How does Python output colored fonts in the CMD command line window

Method 1

The output mode consists of three parts

\033 [font display mode; font color; font background color M ‘character’ \ 033 [0m]

Display mode: 0 (default), 1 (highlight), 22 (non BOLD), 4 (underline), 24 (non underline), 5 (flicker), 25 (non flicker), 7 (reverse display), 27 (non reverse display) font color: 30 (black), 31 (red), 32 (green), 33 (yellow), 34 (blue), 35 (magenta), 36 (cyan), 37 (white) font background color: 40 (black), 41 (red), 42 (green), 43 (yellow), 44 (blue), 45 (magenta), 46 (cyan), 47 (white)

from colorama import init
init(autoreset=True)
name = '谢辰辰'
print(f"\033[0;31m{name}\033[0m")      #Output the red font
print(f"\033[0;31;42m{name}\033[0m") # Output the red font with green background color

Method 2

Setting colors with fore

from colorama import init,Fore
init(autoreset=True)
print (Fore.BLUE+'遇见你') 
print(Fore.RED+'谢辰辰')

Read More: