Python【print】常用颜色(复制用)

字体颜色

yellow = lambda x: print(f'\033[93m{
     x}\033[0m')
e = 'color'
# yellow
print('\033[033m', e, '\033[0m', sep='')
# blue
print('\033[034m', e, '\033[0m')
# purple
print('\033[035m  \033[0m')
# 蓝绿色
print('\033[036m %s \033[0m' % e)
# gray
print('\033[037m%r\033[0m' % e)
# red
print('\033[031m{}\033[0m'.format(e))

背景填充

# background
print('\033[0;7m')
print('\033[0m')
# background yellow
'\033[033;7m{}\033[0m'.format(args)

下划线

# underline
print('\033[0;4m')
print('\033[0m')

文本高亮

w = '比赛'
t = '比赛开始没多久就结束了比赛,现在没有比赛'

def replace_color(text, word):
    new_word = '\033[031m' + word + '\033[0m'  # red
    len_w = len(word)
    len_t = len(text)
    for i in range(len_t - len_w, -1, -1):
        if text[i: i + len_w] == word:
            text = text[:i] + new_word + text[i + len_w:]
    return text

print(t)
print(replace_color(t, w))

写模块

def _wrap_colour(colour, *args):
    for a in args:
        print(colour + '{}'.format(a) + '\033[0m')

def blue(*args): _wrap_colour('\033[94m', *args)
def bold(*args): _wrap_colour('\033[1m', *args)
def cyan(*args): _wrap_colour('\033[96m', *args)
def darkcyan(*args): _wrap_colour('\033[36m', *args)
def green(*args): _wrap_colour('\033[92m', *args)
def pink(*args): _wrap_colour('\033[95m', *args)
def purple(*args): _wrap_colour('\033[035m', *args)
def red(*args): _wrap_colour('\033[91m', *args)
def underline(*args): _wrap_colour('\033[4m', *args)
def yellow(*args): _wrap_colour('\033[93m', *args)

if __name__ == '__main__':
    blue('blue')
    bold('bold')
    cyan('cyan')
    darkcyan('darkcyan')
    green('green')
    pink('pink')
    purple('purple')
    red('r', 'e', 'd')
    underline('underline')
    yellow('yellow')

写类

END = '\033[0m'


class Color:
    @staticmethod
    def _wrap_colour(colour, args, prints, sep):
        if prints:
            for a in args:
                print(colour + '{}'.format(a) + END)  # Linux系统会报错
        return colour + sep.join('{}'.format(a) for a in args) + END

    @classmethod
    def background(cls, *args
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小基基o_O

您的鼓励是我创作的巨大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值