Article Directory
Happy writing code in peacetime, when print will always use, but I believe some people do not know or can set the font color print style, today is the last time this year, Xiao Bian write a blog, Here we teach how to use print to print out the various colors of the New Year
Parameters can print tape
Let's talk about full format print function to print it
print(\033[显示方式;前景色;背景色m输出内容\033[0m)
This is the true face of the original print function, but usually we are using the default format printing
Display method
Display method | effect |
---|---|
0 | default |
1 | Highlight |
22 | Non-bold |
4 | Underline |
24 | Non-underlined |
5 | flicker |
25 | Non-flashing |
7 | Anti-significant |
27 | Non-reverse display |
8 | Invisible |
28 | visible |
Here we look at the results clearly differentiated (0,1,4,5,7)
print("显示方式:")
print("\033[0m新年快乐\033[0m")
print("\033[1m新年快乐\033[0m")
print("\033[4m新年快乐\033[0m")
print("\033[5m新年快乐\033[0m")
print("\033[7m新年快乐\033[0m")
output:
Color Style
Font color numbers | No background color | colour |
---|---|---|
30 | 40 | black |
31 | 41 | red |
32 | 42 | green |
33 | 43 | yellow |
34 | 44 | blue |
35 | 45 | purple |
36 | 46 | Blue color |
37 | 47 | white |
We do not look at the effect of adding background color
print("\033[0;30m新年快乐\033[0m")
print("\033[1;31m新年快乐\033[0m")
print("\033[4;32m新年快乐\033[0m")
print("\033[5;33m新年快乐\033[0m")
print("\033[7;34m新年快乐\033[0m")
print("\033[0;35m新年快乐\033[0m")
print("\033[7;36m新年快乐\033[0m")
print("\033[0;37m新年快乐\033[0m")
output:
Is not it a lot of good-looking, we add background color, font color, here we use upside down, or font color and background color as a can not see the word
print("\033[0;37;40m新年快乐\033[0m")
print("\033[1;36;41m新年快乐\033[0m")
print("\033[4;35;42m新年快乐\033[0m")
print("\033[5;34;43m新年快乐\033[0m")
print("\033[7;33;44m新年快乐\033[0m")
print("\033[0;32;45m新年快乐\033[0m")
print("\033[7;31;46m新年快乐\033[0m")
print("\033[0;30;47m新年快乐\033[0m")
output:
We all finally run it, the way we add back end = '', does not wrap the output looks much more convenient
Finally, I wish you all a happy New Year, extra cash Ha