Python Program To Print Colored Text To The Terminal - Programiz
Maybe your like
To understand this example, you should have the knowledge of the following Python programming topics:
- Python Strings
Example 1: Using ANSI escape sequences
print('\x1b[38;2;5;86;243m' + 'Programiz' + '\x1b[0m')Output
ProgramizThe working of the above line of code is shown in the figure below.
Let's understand the escape code \x1b[38;2;5;86;243m.
- \x1b calls a function. You can also use \033 for the same purpose.
- 38;2;r;g;b helps to set RGB color. 5;86;243 are the rgb color for blue (the color of the logo of Programiz).
- m is the function name. Here, m means SGR (Select Graphics Rendition) function.
For more information regarding the ANSI escape code, you can refer to ANSI escape code.
Example 2: Using python module termcolor
from termcolor import colored print(colored('Programiz', 'blue'))Output
ProgramizUsing the module termcolor, you can get the desired output. Also, you can set different styles of the text using this module.
The first parameter of colored() is the text and the second parameter is the color.
Tag » Color Print Python 3
-
How Do I Print Colored Output With Python 3? - Stack Overflow
-
Print Colors In Python Terminal - GeeksforGeeks
-
How To Print Colored Text In Python - Stack Abuse
-
How To Print Colored Text In Python - Studytonight
-
How To Color Text In Python 3 Code Example
-
Python — Print Colored Text With Ease - Towards Data Science
-
Add Colour To Text In Python
-
Print Colored Text In Python - Linux Hint
-
Texte En Couleur Imprimé En Python | Delft Stack
-
How To Print String In Color On The Console In Python 3
-
How To Print Colored Text In Python (Colorama Tutorial) - YouTube
-
Color Text Output To The Console In Python 3: Colorama And Termcolor
-
Comment Puis-je Imprimer De Couleur De Sortie Avec Python 3?
-
Colored - PyPI