Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses print to print information with colors

Shulou Source: shulou.com Published: 2022-06-01 05:42:48 09月12日 Update

This article mainly introduces python how to use print to print information with color, the article is very detailed, has a certain reference value, interested friends must read it!

Print prints information with color

We all know that the information printing function Print in Python, usually we will use it to print something as a simple debugging.

But did you know that the font color printed by this Print can be set?

A small example

Def esc (code=0): return f'\ 033 [{code} m'print (esc) + 'Error:'+esc () +' important')

You will get the results after running this code on the console or Pycharm.

Error:important

Error is red and underlined, and important is the default color.

The format is:\ 033 [display mode; foreground color; background color m

The following parameters can be set:

Description: foreground color background color-30 40 black 31 41 red 32 42 green 33 43 blue 34 44 blue 35 45 purplish red 36 46 cyan 37 47 white display meaning End default setting 1 highlight 4 use underscore 5 flicker 7 highlight 8 invisible example:\ 033 [1 31Ting 40m and above are all the contents of this article entitled "how python uses print to print information with colors". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Color information example content way scenery article red background blue underline thing code value interest function parameter font boy buddy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Redmi MariaDB Docker