Python output string with color

Source: Internet
Author: User

Outputs a colored string that displays the part to highlight. The test, which is feasible in Pycharm, is not available on the Windows command line. The cause is unknown.

Method:

Format:"\033[display mode; background color m need to change the color of the string \033[display mode M"Example:"\033[1;31;47m requires a variable color string \033[0m"<1-highlight 31 foreground color Red 47 background black--a string that needs to be colored--0-Cancel color settings >Description: Color of foreground background color---------------------------------------30 40Black31 41Red32 42Green33 43Yellow color34 44Blue35 45Purplish Red36 46Cyan Blue37 47meaning of white display mode-------------------------0 Terminal default settings (that is, color settings are canceled)1Highlight Display4Use underline5flashing7anti-white display8 Not visible

Test:

Print ("\033[1;31;40m needs to change the color of the string \033[0m")

Results:

Python output string with color

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.