Console output Color-colored text method:
In the process of Python development, you will often encounter the need to print various kinds of information. The huge amount of information piled up in the console will result in information being mixed together, reducing the readability of important information. At this time, if the important information can be added to the font color, then it will be more convenient for users to read.
Of course, the display of the console is limited, and can not be as cool as the previous paragraph, only to do some simple settings. But from the point of view of readability, it has been much better.
The writing format, and the related instructions are as follows:
#格式: Set Color start: \033[display, foreground color, background m# description: foreground background color --------------------------------------- Black Red, green, yellow, blue, violet, blue, White. meaning------------------------- terminal default setting highlighting with an underscore blinking anti-white display invisible #例子: \033[1;31;40m <!--1-highlight 31-foreground color red 40-background black-->\033[0m <!--with terminal default setting, that is, cancel color settings--
Example 1:
Print (' \033[0;32;40m Welcome to Student selection system \033[0m ') Try: num = int (input (' Enter digital selection function: ') except Exception as E: print (' \ 033[31m I'm sorry! The content you entered is incorrect ~\033[0m ')
Operation Result:
Example 2:
Print (' \033[0;36m firecrackers in the one-year-old except, ') print (' Spring breeze sends warm into the tusujiu. Print (' Thousand Doors million Tong Tong Day, ') print (' Always replace the new peach with the old symbol. \033[0m ')
Operation Result:
Python console colors