How the python terminal outputs colored fonts
Implementation process:
The character color of the terminal is escaped What the sequence controls is the system display function in text mode, and has nothing to do with the specific language.
The escape sequence starts with ESC, which is completed with \033 (the ASCII code of ESC is 27 in decimal and 033 in octal).
Writing format:
Beginning part: \033[Display mode; foreground color; background color m Ending part: \033[0m
Note: The three parameters at the beginning: display mode, foreground color, and background color are optional parameters. You can only write one of them; in addition, since the values that represent the different meanings of the three parameters are unique and not repeated, Therefore, there is no fixed requirement for the writing order of the three parameters, and the system can recognize them; however, it is recommended to write them in the default format. The ending part can actually be omitted, but for the sake of writing standards, it is recommended to start with \033[*** and end with \033[0m
. The meaning of the parameter represented by the numerical value:
Common beginning format:
Example:
The above is the detailed content of How to output colored fonts in the terminal in Python. For more information, please follow other related articles on the PHP Chinese website!