2024-04-26 04:57:43 发布
网友
我正在寻找一种方法,使用户在控制台中键入的文本加粗
input("Input your name: ")
如果我输入“John”,我希望它显示得像我输入的一样粗体,像这样
Input your name: John
它们被称为ANSI转义序列。基本上,您可以输出一些特殊的字节来控制终端文本的外观。试试这个:
x = input('Name: \u001b[1m') # anything from here on will be BOLD print('\u001b[0m', end='') # anything from here on will be normal print('Your input is:', x)
\u001b[1m告诉终端切换到粗体文本。\u001b[0m告诉它重置。你知道吗
\u001b[1m
\u001b[0m
This page很好地介绍了ANSI转义序列。你知道吗
它们被称为ANSI转义序列。基本上,您可以输出一些特殊的字节来控制终端文本的外观。试试这个:
\u001b[1m
告诉终端切换到粗体文本。\u001b[0m
告诉它重置。你知道吗This page很好地介绍了ANSI转义序列。你知道吗
相关问题 更多 >
编程相关推荐