
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Print Colors of terminal in Python
In the terminal, if you want to make some texts appears in colored mode, there are numerous ways in python programming to achieve it.
Using python modules
1.termcolor module: It is the ANSII Color formatting for output in the terminal.
import sys from termcolor import colored, cprint text1 = colored('Hello, Tutorialspoint!', 'blue', attrs=['reverse', 'blink']) print(text1) cprint('Hello, Python!', 'blue', 'on_white') print_red_on_blue = lambda x: cprint(x, 'red', 'on_blue') print_red_on_blue('Hello, from Data Science!') print_red_on_blue('Hello, Python!') for i in range(10): cprint(i, 'green', end=' ') cprint("Attention!", 'blue', attrs=['bold'], file=sys.stderr)
Result
- Related Articles
- How to use rainbow colors in linux terminal
- Sort Colors in Python
- Terminal Control Functions in Python
- Pseudo-terminal Utilities in Python
- Shortest Path with Alternating Colors in Python
- Formatted text in Linux Terminal using Python
- How to plot histograms of different colors of an image in OpenCV Python?
- Psychological Effects of Colors
- Difference Between Additive Colors and Subtractive Colors
- Program to find minimum number colors remain after merging in Python
- Bash Terminal Redirect to another Terminal
- Defining Colors in CSS3
- How to open new pseudo-terminal pair using Python?
- Print Words Vertically in Python
- Print a Calendar in Python

Advertisements