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")
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")
>>> print("\u2764\ufe0f")
❤️
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.)
Neither of the two unicodes worked for me - they both printed black hearts. The red heart requires combining the two unicodes:
print("\u2764\uFE0F")
Explanation for why it requires two unicodes can be found here.
>>> print("\u2764\ufe0f")
❤️
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.)
© 2022 - 2024 — McMap. All rights reserved.
print(c1 + c2)
. – Wolff