Home  >  Article  >  Backend Development  >  How to output colored fonts in the terminal in Python

How to output colored fonts in the terminal in Python

silencement
silencementOriginal
2019-05-23 14:36:012846browse

How to output colored fonts in the terminal in Python

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:

How to output colored fonts in the terminal in Python

Common beginning format:

How to output colored fonts in the terminal in Python

Example:

How to output colored fonts in the terminal in Python

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn