E.g:
print "hello"
我该怎么做才能将“hello”文本加粗?
E.g:
print "hello"
我该怎么做才能将“hello”文本加粗?
当前回答
粗体印刷变得很容易。
使用pip安装quo:
from quo import echo
echo(f"Hello, World!", bold=True)
其他回答
假设你指的是真正的打印终端上的“打印”:
>>> text = 'foo bar\r\noof\trab\r\n'
>>> ''.join(s if i & 1 else (s + '\b' * len(s)) * 2 + s
... for i, s in enumerate(re.split(r'(\s+)', text)))
'foo\x08\x08\x08foo\x08\x08\x08foo bar\x08\x08\x08bar\x08\x08\x08bar\r\noof\x08\
x08\x08oof\x08\x08\x08oof\trab\x08\x08\x08rab\x08\x08\x08rab\r\n'
把它发送到你的stdout。
这取决于你使用的是Linux还是Unix:
>>> start = "\033[1m"
>>> end = "\033[0;0m"
>>> print "The" + start + "text" + end + " is bold."
The text is bold.
“text”这个词应该加粗。
粗体印刷变得很容易。
使用pip安装quo:
from quo import echo
echo(f"Hello, World!", bold=True)
简单的粗体-两行代码
在Python 3中,你可以使用Colorama - simple_colors: (在简单颜色页面*,转到标题“用法”。)在你做下面的事情之前。确保你安装了simple_colors。
from simple_colors import *
print(green('hello', 'bold'))
def say(text: str):
print ("\033[1;37m" + text)
say("Hello, world!")
我的代码工作正常。