Python-print骚操作之不一样的打印风格

目录

风格字符输出

给点颜色瞧瞧

print原生

termcolor库

colorama库


风格字符输出

from rich import print as rprint
st = r'''
         ________  ___    ___ _________  ___  ___  ________  ________           ________  _________    ___    ___ ___       _______      
        |\   __  \|\  \  /  /|\___   ___\\  \|\  \|\   __  \|\   ___  \        |\   ____\|\___   ___\ |\  \  /  /|\  \     |\  ___ \     
        \ \  \|\  \ \  \/  / ||___ \  \_\ \  \\\  \ \  \|\  \ \  \\ \  \       \ \  \___|\|___ \  \_| \ \  \/  / | \  \    \ \   __/|    
         \ \   ____\ \    / /     \ \  \ \ \   __  \ \  \\\  \ \  \\ \  \       \ \_____  \   \ \  \   \ \    / / \ \  \    \ \  \_|/__  
          \ \  \___|\/  /  /       \ \  \ \ \  \ \  \ \  \\\  \ \  \\ \  \       \|____|\  \   \ \  \   \/  /  /   \ \  \____\ \  \_|\ \ 
           \ \__\ __/  / /          \ \__\ \ \__\ \__\ \_______\ \__\\ \__\        ____\_\  \   \ \__\__/  / /      \ \_______\ \_______\
            \|__||\___/ /            \|__|  \|__|\|__|\|_______|\|__| \|__|       |\_________\   \|__|\___/ /        \|_______|\|_______|
                 \|___|/                                                          \|_________|       \|___|/                                                                                                                                                                                                     
'''
rprint(f'[green]{st}[/green]')

字符生成器,拿走直接用:http://www.patorjk.com/software/taag/,输入生成后直接复制就可,简单好用,值得拥有

给点颜色瞧瞧

print原生

print("\33[1;32;43m就是这么骚,不容反驳")  # 0;32;43  (粗细—0为细,1为粗;字体颜色;背景颜色)

  

  

# 上面的例子没有设置结束,设置结束需要在结束处将背景颜色设置为0m
print("\33[1;32;43m就是这么骚,不容反驳\33[1;32;0m") 

 

 字体颜色和背景颜色设置对照此表

termcolor库

使用一下两个原函数

def colored(text, color=None, on_color=None, attrs=None):
def cprint(text, color=None, on_color=None, attrs=None, **kwargs):

colored方法

from termcolor import colored, cprint
print(colored('中国', 'blue'), colored('红', 'red'))
text = colored('Python骚操作', 'red', attrs=['reverse', 'dark'])
print(text)

  

cprint方法

from termcolor import colored, cprint

cprint('Python骚操作', 'green', 'on_yellow')
# 生成一个方法函数方便直接调用
my_print = lambda x: cprint(x, 'white', 'on_green')
my_print('print骚操作之一')
my_print('print骚操作没有最好,只有更好')

  

colorama库

样式设置之后对后面的所有输出都产生影响,需要取消时进行重置操作

from colorama import Fore, Back, Style

print(Fore.YELLOW + '设置文字字体颜色')
print(Back.WHITE + '设置背景颜色', Fore.RED, '背景颜色和字体设置后的结果,受前面最近的一个设置影响')
print(Style.BRIGHT + '设置字体样式')
print(Style.RESET_ALL, end='')  # 重置所有设置
print('重置后的打印结果')

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值