Skip to content
Advertisement

How to print red heart in python 3

I need to print the red heart emoji ❤️️ with unicode in Python 3 but it has two unicodes (U00002764 and U0000FE0F). How am I suppose to print it?

For example, a green heart is print("U0001F49A")

Advertisement

Answer

>>> print("u2764ufe0f")
❤️

Whether it “works” depends on the font you have and which glyphs it supports. Here’s the same character in a non-code font (literally copy/pasted from the above):

❤️

In some more detail, U+2764 is HEAVY BLACK HEART and typically renders as a black heart: ❤

U+FE0F is VARIATION SELECTOR 16 which is a combining character which modifies the previous character, in this case to turn the heart red.

Neither of these code points has more than four hex digits so using the long-hand U00000000 form is unnecessary.

(For what it’s worth, in the text above, I see a black heart in the code font, and a red one in the regular body text font. In the MacOS Terminal, the red heart renders in a different font, so there I see it as a red heart in the Python REPL, too.)

Screen shot showing how the character renders, MacOS Catalina

Advertisement