f = {'red':'31m', 'green':'32m', 'yellow':'33m', 'blue':'34m', 'magenta':'35m', 'cyan':'36m', 'lightgray':'37m', 'darkgray':'90m', 'white':'97m'} def colorize(color, text): colortext=f'\033[{color}{text}\033[00m' return colortext print(colorize(f['red'], 'Hello, World!') # Hello, World! (In Red) # Alternatively, a function wrapper for each specific color can easily be dropped into any project... def red(text): # Will print in Red colortext = f'\033[31m{text}\033[00m' return colortext def blue(text): # Will Print in Blue colortext = f'\033[34m{text}\033[00m' return colortext def magenta(text): colortext = f'\033[35m{text}\033[00m' return colortext def cyan(text): colortext = f'\033[36m{text}\033[00m' return colortext