📜  在 python 代码示例中为文本添加颜色

📅  最后修改于: 2022-03-11 14:46:57.241000             🧑  作者: Mango

代码示例1
def colored(r, g, b, text):
    return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
  
text = 'Hello, World'
colored_text = colored(255, 0, 0, text)
print(colored_text)

#or

print(colored(255, 0, 0, 'Hello, World'))