You can print text in Terminal (Console) in Python using ANSI Codes.
Below are a few examples of color codes:
color_blue_ANSI_code = '\033[94m'
color_red_ANSI_code = '\033[91m'
color_green_ANSI_code = '\033[92m'
color_yellow_ANSI_code = '\033[93m'
You will need to reset the color, to choose another one or default back to white.
reset_color = '\033[0m'
Example:
''' Colored Text Example
By: Code2care.org
'''
#
color_blue_ANSI_code = '\033[94m'
color_red_ANSI_code = '\033[91m'
color_green_ANSI_code = '\033[92m'
color_yellow_ANSI_code = '\033[93m'
# Reset color code
reset_color = '\033[0m'
# Print colored text
print(color_red_ANSI_code + 'This will be printed in Red Color' + reset_color)
print(color_blue_ANSI_code + 'Blue blue Skies!!' + reset_color)
print(color_yellow_ANSI_code + '...and it was all Yellow!' + reset_color)
print(color_green_ANSI_code + 'The World Needs to Go Green!' + reset_color)
Terminal Output:

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python-Programs,
- Program 5: Find Sum of Two Integer Numbers - 1000+ Python Programs
- 34: Traverse a List in Reverse Order - 1000+ Python Programming
- 22: Send Yahoo! Email using smtplib - SMTP protocol client using Python Program
- 35: Python Program to find the System Hostname
- 27: Measure Elapsed Time for a Python Program Execution
- Program 7: Find Difference of Two Numbers - 1000+ Python Programs
- Program 12: Calculate Area and Circumference of Circle - 1000+ Python Programs
- Program 9: Divide Two Numbers - 1000+ Python Programs
- Program 2: Print your name using print() function - 1000+ Python Programs
- 25: How to rename a file using Python Program
- 17: Find Factorial of a Number - 1000+ Python Programs
- Program 6: Find Sum of Two Floating Numbers - 1000+ Python Programs
- 23: Python Programs to concatenate two Lists
- 36: Python Program Convert Hex String to Integer
- 20 - Python - Print Colors for Text in Terminal - 1000+ Python Programs
- Python Program: Use NumPy to generate a random number between 0 and 1
- 32: Python Program to Find Square Root of a Number
- Program 8: Multiply Two Numbers - 1000+ Python Programs
- Program 11: Calculate Percentage - 1000+ Python Programs
- 18: Get Sub List By Slicing a Python List - 1000+ Python Programs
- 28: Program to Lowercase a String in Python
- Program 1: Print Hello World! - 1000+ Python Programs
- 21: Program to Delete File or Folder in Python
- 29: Program to convert Python dict to dataframe
- 33: Python Program to find the current time in India (IST)
More Posts:
- Install Docker Desktop on M1/M2 Apple Silicon ARM Chip Mac - Docker
- How to read Huge Text Files in Notepad++ (CSV, JSON or XML) - NotepadPlusPlus
- Eclipse version 32-bit or 64-bit check on macOS - Eclipse
- How to convert a Excel to PDF file in Mac - MacOS
- Solution: AWS S3 CLI Command AccessDenied - S3
- How to display an Image in Python - Python
- Python: Pandas Rename Specific Column names in DataFrame Example - Python
- Limit scrollback rows in macOS Terminal - MacOS