Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Unicode – Can't print some unicode characters

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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')
😀
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading