0

I want to change color of text. And when I try it in VS code it works. But when I try it in CMD in Windows I get this:

←[91mstring

Code in python:

print ('\033[91m' + "string")
martineau
  • 119,623
  • 25
  • 170
  • 301

2 Answers2

1

There is a "bug" in cmd. You need to first clear the screen with:

import os
os.system("cls")

Than it should work.

Full code:

import os
os.system("cls")

print('\033[91m' + "string")

I hope my answer will help.

Halina20011
  • 26
  • 1
  • 3
0

This is how to use it properly :

import os
os.system("cls")

print('\033[91m' + "string")

There is also the Python termcolor module. Usage is pretty simple:

from termcolor import colored

print(colored('string', 'red'), colored('string', 'green'))
MrMRM
  • 1
  • 1
  • 2