How to print colored text in terminal in Python?

0 votes

How can I output colored text to the terminal in Python? What is the best Unicode symbol to represent a solid block?

Jun 5 in Python by kartik
• 15,440 points
136 views

1 answer to this question.

0 votes

Hello @kartik,

You can use  Python termcolor module. Usage is pretty simple:

from termcolor import colored

print colored('hello', 'red'), colored('world', 'green')

Or in Python 3:

print(colored('hello', 'red'), colored('world', 'green'))

It may not be sophisticated enough, however, for game programming and the "colored blocks" that you want to do.

Hope it works!!

answered Jun 5 by Niroj
• 32,200 points

Related Questions In Python

+2 votes
11 answers
+1 vote
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
4,550 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 4, 2018 in Python by Omkar
• 69,040 points

edited Aug 8, 2018 by Omkar 3,590 views
+1 vote
1 answer

How to print an error in Python?

For Python 2.6 and later and Python ...READ MORE

answered Aug 23, 2018 in Python by Priyaj
• 57,530 points
583 views
0 votes
3 answers

Python Selenium best tutorials for beginners

Hope this will help you...Python Tutorial READ MORE

answered Feb 11, 2019 in Python by aldrinjohn
• 140 points
1,985 views
0 votes
1 answer

How to create a zip archive of a directory in Python?

Hello @kartik, The easiest way is to use shutil.make_archive. ...READ MORE

answered May 11 in Python by Niroj
• 32,200 points
28 views
0 votes
1 answer

How to reimport an updated package while in Python Interpreter?

Hello, To import an updated package while in ...READ MORE

answered May 11 in Python by Niroj
• 32,200 points
47 views