How Python outputs colors and styles

Source: Internet
Author: User

Last encounter this problem want to write down, in fact, I did not very much, the teacher said this thing does not need to understand, only need to memorize, write a lot of remember, so today collected a few articles, plus their own understanding, wrote this python output color style and method of the article, On the one hand want to record their own understanding, on the other hand want to use their own popular understanding to the needs of the pot friends.

In writing the Python program code, we know that the string color of Python output is the same as the normal character, but many times we need to emphasize certain characters and need to make them easily recognizable colors or noticeable. It also collects a color-added format,

format: "\033[word background color; font Color m ———————— \033[0m" (—————— means string)

For example: "\033[42;37m there is ready color\033[0m"

Format: \033[display mode; foreground color; background colour m Description: foreground color background color---------------------------------------30 40Black31 41Red32 42Green33 43Yellow color34 44Blue35 45Purplish Red36 46Cyan Blue37 47meaning of white display mode-------------------------0 Terminal default settings1Highlight Display4Use underline5flashing7anti-white display8example not visible: \033[1;31;40m <!--1-highlight 31-foreground color Red 40-background black--\033[0m <!--Use the terminal default setting, which cancels the color setting--(This procedure is directly copied by someone else to write well, feel much better than I write, and comprehensive)

For example, here a small number of the program, if the correct guess, the result is normal, if the guess is not correct, the results are color-coded to help you improve

_author_ ="Zhanzhengrecheng" forIinchRange (4): number= Input ("input one number:") number=Int (number)ifNumber >56:        Print("\033[37;44m yes,%s is really bigger than 56 \033[0m"%Number )elifNumber = = 56:        Print("congratulation your input the number is true")         Break    Else:        Print('\033[34;43m no,%s 56 small \033[0m'%Number )Else:    Print("your chances are running out.")

Code results:

Input one number:49 no,49 56 Small inputone number: yes,59 is indeed 56 large inputone number: True

How Python outputs colors and styles

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.