Ask coding questions

← Back to all posts
Color Confusions
PattanAhmed (1384)

Hi,
See, This is my commands on a color string in Python.
As you all can see that I wrote print(Pink + "Hello") in First Line and print("Ok") in the second line.

But when I run this commands my second line string is also turning Pink even though I didn't mention Pink there...
Why is it happening?
Is there a solution to it?

Thanks,
Waiting for Replies!

Answered by Bookie0 (5645) [earned 5 cycles]
View Answer
Comments
hotnewtop
Bookie0 (5645)

Hey, do this after the color imports:

END = '\033[0m'

Then to print the thing, do this:

print (Pink + “Hello” + END)
print(“ok”)

The END should not make ok pink

Hope this helps!

PattanAhmed (1384)

@Bookie0 Thanks a lot, It worked fine
Just a small mistake you did is you have put " before Pink
Remove that, Then I will mark your answer as the correct answer!

Bookie0 (5645)

Oh yeah whoops, typo. I made it correct now!
=) @PattanAhmed

PattanAhmed (1384)

@Bookie0
I was needing that answer for so long.
Thanks a Lot

Bookie0 (5645)

Yeah sure np thanks for selecting my answer! =) @PattanAhmed

TheForArkLD (760)

This is pink. in repl some color is not true color.

PattanAhmed (1384)

@TheForArkLD THEN WHAT ARE THE TRUE COLORS IN PYTHON?

PattanAhmed (1384)

@TheForArkLD It can be possible dude...
There will be of course some way!
I will find it out

TheForArkLD (760)

@PattanAhmed Lol no, but really no way to display true color by this.

TheForArkLD (760)

@PattanAhmed Good idea. use it
( replace n to 0 ~ 255 )
Text : \x1b[38;5;nm
Background : \x1b[48;5;nm

TheForArkLD (760)

@PattanAhmed but you need find pink from 0 ~ 255.

PattanAhmed (1384)

@TheForArkLD Can you please send me your code,
I will try it.

TheForArkLD (760)

@PattanAhmed try it in js

for(var i=0;i < 256;i++){
console.log("\u001b[48;5;" + i + "m" + i + "\u001b[m");
}
PattanAhmed (1384)

@TheForArkLD I need Python Code not JavaScript.
Thanks!

TheForArkLD (760)

@PattanAhmed ye. run this js for know code.