Python console colors

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.