Home > Backend Development > Python Tutorial > Python implementation of outputting colored string case analysis

Python implementation of outputting colored string case analysis

黄舟
Release: 2017-10-10 10:49:55
Original
2217 people have browsed it

下面小编就为大家带来一篇Python输出带颜色的字符串实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

输出带颜色的字符串,用来显示要突出的部分。经测验,在pycharm中可行,在windows命令行中不可行。原因未知。

方法:


格式:"\033[显示方式;前景色;背景色m 需要变颜色的字符串 \033[显示方式m"
例子:"\033[1;31;47m 需要变颜色的字符串 \033[0m"
<1-高亮显示 31前景色红色 47背景色黑色--需要变颜色的字符串--0-取消颜色设置>

说明:
前景色   背景色   颜色
---------------------------------------
    40    黑色
    41    红色
    42    绿色
    43    黃色
    44    蓝色
    45    紫红色
    46    青蓝色
    47    白色
显示方式   意义
-------------------------
    终端默认设置(即取消颜色设置)
    高亮显示
    使用下划线
    闪烁
    反白显示
    不可见
Copy after login

测试:

print("\033[1;31;40m需要变颜色的字符串\033[0m")

结果:

The above is the detailed content of Python implementation of outputting colored string case analysis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template