Bold formatting in Python console
14,364
Solution 1
You need to also specify END = '\033[0m'
:
list = ['kumar','satheesh','rajan']
BOLD = '\033[1m'
END = '\033[0m'
for each in list:
print('{}{}{}'.format(BOLD, each, END))
To make the list itself bold like ['kumar', 'satheesh', 'rajan']:
print('{}{}{}'.format(BOLD, list, END))
Solution 2
try printing as follows
for each in list:
print(each)
Related videos on Youtube
![mvsat](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=256)
Author by
mvsat
Updated on June 04, 2022Comments
-
mvsat about 2 years
I have defined a list in Python code.
list = ['kumar','satheesh','rajan'] BOLD = '\033[1m' for i, item in enumerate(list): list[i] = BOLD + item print (list)
But I am getting the
output as ['\x1b[1mfsdfs', '\x1b[1mfsdfsd', '\x1b[1mgdfdf']
But the required output is
['kumar','satheesh','rajan']
How to
format
thelist elements
inbold
usingpython
?-
imperialgendarme about 6 yearsPlease consider using a different variable name for your list.. list is not an enforced keyword but it will give you unforeseeable problems if you use that as your variable name..
-
smci about 6 yearsPossible duplicate of How do I print colored/bold output to the terminal in Python?
-
mkHun about 6 yearsYou are making the bold for square bracket also if it is really want print bold before printing the array
-
-
Serge Ballesta about 6 yearsI did not downvote, and I know that it will work. But code only answers are considered as poor on SO. Explaining why it works that way will greatly improve your answer...
-
smci about 6 yearsPlease close as duplicate How do I print colored/bold output to the terminal in Python?
-
Ancora Imparo about 6 yearsYour code will print all outputs in bold even if an item doesn't prefix with the escape string because it didn't ends with '\033[0m'.
-
mvsat about 6 yearsI need the output to be enclosed in list. Inside the list only, the bold letters are not coming
-
mvsat about 6 yearsI need the output to be enclosed in list. Inside the list only, the bold letters are not coming @Kalyan
-
mvsat about 6 yearsWow! It helps. Thanks.
-
rawwar about 6 yearsare you trying to do it in ipython console?