'Colored text in command prompt after "cls" but not before "cls"

I have a python program where I am trying to print "Hello" in colored text using ANSI codes in command prompt. When I print in normally, it is not working, it just prints ? and text, but when I print it after clearing the command prompt it works fine. Can some one explain this weird nature.

I searched for this but couldn't find anything about this nature. I am using Windows 10

The below code outputs [0;32mHello[0m

print('\x1b[0;32m' + "Hello" + '\033[0m')

no color

whereas the below code outputs Hello in green color.

os.system("cls")
print('\x1b[0;32m' + "Hello" + '\033[0m')

Right image is the output of the code shown above or in the left image enter image description here  enter image description here

My expectation was that is gives either ansii or colored text in both the above codes, but actual output is different in both the cases



Solution 1:[1]

try this:

os.system("")
print('\x1b[0;32m' + "Hello" + '\033[0m')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Izaz