Tom Liu
Tom Liu

Reputation: 45

How to print green heart symbol in Python?

I want to print the green heart with this script: print('\u1F49A'). But it shows ὉA`. So what went wrong and what is the right way to print the green heart?

Upvotes: 1

Views: 1187

Answers (2)

Tomak
Tomak

Reputation: 31

print("\u001b[32m\u2764")

print("\u001b[32m\U0001F49A")

Upvotes: 1

Mark
Mark

Reputation: 92460

'\u1F49' is Greek Capital Letter Omicron with Dasia: Ὁ. '\u1F49A' is that same character plus an A literal. This is because \u expects a 16-bit hex value, or 4 hex characters. If you want to pass in a larger value you need to use capital \U and pass in the full 32-bit hex value:

print('\U0001F49A')
# 💚

See the python docs for more info

Upvotes: 4

Related Questions