E.g:

print "hello"

我该怎么做才能将“hello”文本加粗?


当前回答

粗体印刷变得很容易。

使用pip安装quo:

from quo import echo
echo(f"Hello, World!", bold=True)

其他回答

class color:
   PURPLE = '\033[95m'
   CYAN = '\033[96m'
   DARKCYAN = '\033[36m'
   BLUE = '\033[94m'
   GREEN = '\033[92m'
   YELLOW = '\033[93m'
   RED = '\033[91m'
   BOLD = '\033[1m'
   UNDERLINE = '\033[4m'
   END = '\033[0m'

print(color.BOLD + 'Hello, World!' + color.END)

这取决于你使用的是Linux还是Unix:

>>> start = "\033[1m"
>>> end = "\033[0;0m"
>>> print "The" + start + "text" + end + " is bold."
The text is bold.

“text”这个词应该加粗。

你可以使用termcolor来表示:

 sudo pip install termcolor

打印彩色粗体:

 from termcolor import colored
 print(colored('Hello', 'green', attrs=['bold']))

有关更多信息,请参阅PyPi上的termcolor。

Simple-colors是另一个具有类似语法的包:

 from simple_colors import *
 print(green('Hello', ['bold'])

在colorama中对应的可能是Style.BRIGHT。

print '\033[1m  Your Name  \033[0m'

\033[1m是终端中粗体的转义码。 \033[0m是结束编辑文本并返回默认文本格式的转义代码。

如果你不使用\033[0m],那么所有即将出现的终端文本都将变成粗体。

粗体文本在Python中是这样的:

print("This is how the {}bold{} text looks like in Python".format('\033[1m', '\033[0m'))

这就是Python中粗体文本的样子。