在Python中,可以通过使用ANSI转义码来输出彩色文本。以下是一些常用的ANSI转义码:
红色:\033[91m绿色:\033[92m黄色:\033[93m蓝色:\033[94m紫色:\033[95m青色:\033[96m示例代码如下:
print("\033[91mThis is red text\033[0m")print("\033[92mThis is green text\033[0m")print("\033[93mThis is yellow text\033[0m")print("\033[94mThis is blue text\033[0m")print("\033[95mThis is purple text\033[0m")print("\033[96mThis is cyan text\033[0m")在上面的示例中,\033[0m用于重置颜色,使后续文本恢复默认颜色。可以根据需要在文本中插入不同的颜色代码来输出不同颜色的文本。


