python输出字体颜色_Python通过2种方法输出带颜色字体
方法1:
使用Python中自带的print输出带有颜色或者背景的字符串
书写语法
print(\033[显示方式;前景色;背景色m输出内容\033[0m)
其中,显示方式、前景色、背景色都是可选参数(可缺省一个或多个)。
参数
显示方式
显示方式
效果
0
默认
1
粗体
4
下划线
5
闪烁
7
反白显示
print("显示方式:")
print("\033[0mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[1mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[4mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[5mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[7mSuixinBlog: https://suixinblog.cn\033[0m")
颜色
字体色编号
背景色编号
颜色
30
40
黑色
31
41
红色
32
42
绿色
33
43
黄色
34
44
蓝色
35
45
紫色
36
46
青色
37
47
白色
print("字体色:")
print("\033[30mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[31mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[32mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[4;33mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[34mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[1;35mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[4;36mSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37mSuixinBlog: https://suixinblog.cn\033[0m")
print("背景色:")
print("\033[1;37;40m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37;41m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37;42m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37;43m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37;44m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37;45m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[37;46m\tSuixinBlog: https://suixinblog.cn\033[0m")
print("\033[1;30;47m\tSuixinBlog: https://suixinblog.cn\033[0m")
方法2:
colorama是一个python专门用来在控制台、命令行输出彩色文字的模块,可以跨平台使用。
1. 安装colorama模块
pip install colorama
可用格式常数:
Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Back: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.
Style: DIM, NORMAL, BRIGHT, RESET_ALL
跨平台印刷彩色文本可以使用彩色光的常数简称ANSI转义序列:
from colorama import Fore,Back,Style
print (Fore.RED + "some red text")
print (Back.GREEN + "and with a green background")
print (Style.DIM + "and in dim text")
print (Style.RESET_ALL)
print ("back to normal now!!")
Init关键字参数:
init()接受一些* * kwargs覆盖缺省行为
init(autoreset = False):
如果你发现自己一再发送重置序列结束时关闭颜色变化每一个打印,然后init(autoreset = True)将自动化
示例:
from colorama import init,Fore
init(autoreset=True)
print (Fore.RED + "welcome to python !!")
print ("automatically back to default color again")
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
python输出字体颜色_Python通过2种方法输出带颜色字体相关推荐
- python无法输出有颜色的字体_Python通过2种方法输出带颜色字体
方法1:PLW免费资源网 使用Python中自带的print输出带有颜色或者背景的字符串PLW免费资源网 书写语法PLW免费资源网 print(\033[显示方式;前景色;背景色m输出内容\033[0 ...
- Python输出所有水仙花数(3种方法)
输出所有水仙花数(3种方法) print(*list(map(lambda x: x[1], filter(lambda x: x[0], [(i**3+j**3+k**3 == i*100+j*10 ...
- python中pca算法_Python使用三种方法实现PCA算法
主成分分析(PCA) vs 多元判别式分析(MDA) PCA和MDA都是线性变换的方法,二者关系密切.在PCA中,我们寻找数据集中最大化方差的成分,在MDA中,我们对类间最大散布的方向更感兴趣. 一句 ...
- python杨辉三角形10行_python杨辉三角形两种方法
1 / \ 1 1 / \ / \ 1 2 1 / \ / \ / \ 1 3 3 1 / \ / \ / \ / \ 1 4 6 4 1 / \ / \ / \ / \ / \ 1 5 10 10 ...
- python类与函数编程_Python类三种方法,函数传参,类与实例变量(一)详解
1 Python的函数传递: 首先所有的变量都可以理解为内存中一个对象的'引用' a = 1 def func(a): a = 2 func(a) print(a) # 1 a = 1 def fun ...
- python格式化字符串漏洞_Python字符串格式化的方法(两种)
本文介绍了Python字符串格式化,主要有两种方法,分享给大家,具体如下 用于字符串的拼接,性能更优. 字符串格式化有两种方式:百分号方式.format方式. 百分号方式比较老,而format方式是比 ...
- python调用shell命令-在Python中执行shell命令的6种方法,你都知道吗?
原标题:在Python中执行shell命令的6种方法,你都知道吗? Python经常被称作"胶水语言",因为它能够轻易地操作其他程序,轻易地包装使用其他语言编写的库.今天我们就讲解 ...
- python使用教程cmd啥意思-对python中执行DOS命令的3种方法总结
1. 使用os.system("cmd") 特点是执行的时候程序会打出cmd在Linux上执行的信息. import os os.system("ls") 2. ...
- python运行命令_对python中执行DOS命令的3种方法总结
1. 使用os.system("cmd") 特点是执行的时候程序会打出cmd在Linux上执行的信息. import os os.system("ls") 2. ...
最新文章
- KubeCon 2020 演讲集锦|《阿里巴巴云原生技术与实践 13 讲》开放下载
- LeetCode 2148. 元素计数
- 小学计算机课评课用语,信息技术评课心得
- uvm 形式验证_谈一谈IC flow中的形式验证
- Mongodb删除重复数据
- LINUX下载ant源码并编译
- 番茄助手破解找到VA_X.dll的位置
- Apex弹窗闪退报错问题解决方案清晰讲解(系统软件层面解决,已亲测可行)
- linux系统时间与网络时间不同步
- keyshot怎么贴logo_KeyShot实例渲染技巧教程,教你如何给产品添加有织纹的Logo
- Python 爬取QQ音乐个人单曲排行榜
- 高并发之阿里云弹性伸缩的使用记录
- 明源软件诚聘.NET软件开发工程师
- 白小小的可爱伤感空间日志发布:有些人,注定只是过客
- 打豆豆游戏c语言编程,《C语言及程序设计》实践参考——打豆豆
- oracle 人民币符号,人民币的符号的正确表示法?一杠?两杠?
- 01 PhantomReference没有进入ReferenceQueue
- 音视频学习之ffmpeg常用基础命令整理
- Oracle LiveLabs实验: Pluggables, Clones and Containers: Oracle Multitenant Fundamentals Workshop
- 饿了么UI/element Popconfirm气泡确认框 confirm事件