Ask coding questions

← Back to all posts
Quirk in Python ANSI Escape Sequence


I have been working extensively with ANSI Escape Sequences in Python3 for my current project and I noticed that the escape code for yellow/orange appears differently depending on which console the program is run in.

Test Code

Disclaimer: I am using f-string formatting because it's awesome and usually the best technique for string formatting.


When I run the program in the console next to the programming environment, here is the output:

But when I run the program in the console, this is the output:


As you can see, one is orange and one is yellow. My question is what causes this and is it a specific problem. If so, why does this only happen on and can we get support for being able to use orange and yellow in the same program?

Answered by sugarfi [earned 5 cycles]
View Answer

This is not a repl specific problem as far as I know. Different terminals have different color schemes - I guess the domains use a different one than the normal repl.


@sugarfi Thanks for the response! Do you know if there is anyway to manipulate the color scheme of terminal, such as adding some code before the program? It also seems weird to me that would have inconsistent color schemes, but maybe the problem lies in the interpretation of the ANSI escape sequences.

I did some more research and I think I get it. Each terminal has 8 slots of colors that can be utilised - when you choose '\033[36m', you are using the color in the 7th slot (0 to 7). I think has orange in the 4th slot for one terminal and yellow in the 4th slot for another terminal, causing the inconsistency.


@Roar123 unfortunately, there is no way to change the terminal's color scheme short of editing the source code for


@Roar123 One thing - you are slightly off with the slots. There are 7 slots, but the numbers are not simply random. Each is a form of RGB color. The bits in any particular number determine the red, green, and blue. Take yellow, for example: slot number 3 if you count from 0. 3 in binary is 110. Thus, the red amount is 255, the green is 255, and the blue is 0. This gives us yellow. However, some terminals use different amounts of red green a blue, so you might have (255, 128, 0) or (128, 128, 0) for 3.


@sugarfi Ok, thanks!


@Roar123 no problem! Also, yeah, f-strings are awesome.


That's weird?Ive never seen that


@iterate I know right!