Python控制台中的粗体格式

Sat*_*mar 2 python console ansi output-formatting

我已经在Python代码中定义了一个列表。

list = ['kumar','satheesh','rajan']    
BOLD = '\033[1m'

for i, item in enumerate(list):
   list[i] = BOLD + item

print (list)
Run Code Online (Sandbox Code Playgroud)

但是我正在 output as ['\x1b[1mfsdfs', '\x1b[1mfsdfsd', '\x1b[1mgdfdf']

但是所需的输出是 ['kumar','satheesh','rajan']

如何formatlist elementsbold使用python

Aus*_*tin 5

您还需要指定END = '\033[0m'

list = ['kumar','satheesh','rajan']

BOLD = '\033[1m'
END = '\033[0m'

for each in list:
    print('{}{}{}'.format(BOLD, each, END))
Run Code Online (Sandbox Code Playgroud)

为了使列表本身像['kumar','satheesh','rajan']那样大胆:

print('{}{}{}'.format(BOLD, list, END))
Run Code Online (Sandbox Code Playgroud)