I was trying to print random Unicode characters in Jupyter Notebook. In general, I am able to print characters but there are many which I can’t print. Although I couldn’t keep track of other examples, the following one is the I was able to reproduce –
str('\u1F600') #o/p is 'ὠ0' but actually it is a Grinning Face
I remember that in at least 2 other cases, the output was some character followed by 0.
I am using Python 3.9 on Windows 8. What am I doing wrong?
>Solution :
\u only accepts 4 digits, so your string literal is being parsed as two separate characters, \u1f60 and 0.
>>> print('\u1f60')
ὠ
>>> print('0')
0
For larger code points, you need to use \U (which requires 8 digits, including leading 0s).
>>> print('\U0001f600')
😀