Python 带颜色字体的打印
带颜色字体的打印
原理不做描述,封装后的函数如下所示
# -*- coding: utf-8 -*-
"""带颜色打印输出;
"""
def print_white(s: str):
"""白色字体打印;
"""
print(f"\033[30m{s}\033[0m")
def print_red(s: str):
"""
红色的输出;
:param s:
:return:
"""
print(f"\033[31m{s}\033[0m")
def print_green(s: str):
"""绿色字体的输出;
"""
print(f"\033[32m{s}\033[0m")
def print_yellow(s: str):
"""黄色字体打印;
"""
print(f"\033[33m{s}\033[0m")
def print_blue(s: str):
"""蓝色字体的打印;
"""
print(f"\033[34m{s}\033[0m")
def print_purplish(s: str):
"""紫红色字体打印;
"""
print(f"\033[35m{s}\033[0m")
def print_cyan(s: str):
"""青色字体的打印;
"""
print(f"\033[36m{s}\033[0m")
def print_black(s: str):
"""黑色字体打印;
"""
print(f"\033[37m{s}\033[0m")
if __name__ == '__main__':
print_green("Hello World")
继续努力,终成大器!