python cmd colors code example

Example 1: how to change the color of command prompt in python

import os
# To get all possible colors for the command line, open the command prompt
# and enter the command "color help"
os.system('color FF')

Example 2: python cmd colors

from colorama import init
from colorama import Fore, Back, Style

init()

print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Style.RESET_ALL)
print('back to normal now')
# or
print('\033[31m' + 'some red text')
print('\033[39m') # and reset to default color