fabiob
fabiob

Reputation: 295

Why the same command prints an emoji in python 2 but fails in python 3?

In python 2.7:

print('\xF0\x9F\x98\x9E')

prints a sad emoticon. The same command fails in python 3.5 (prints some squares). Why and how can I solve it?

Using the emoji package did not work either:

import emoji

print(emoji.emojize('Python is :thumbs_up_sign:'))

print(emoji.emojize('Python is :cookie:'))

also print squares. I tried to follow the suggestions here Difference between python 2 and 3 for utf-8 (thanks to @lenz) but if I type:

print(u"\1F61E") or print(u"\u1F61E")

I still do not get my emoticon.

Upvotes: 0

Views: 474

Answers (1)

fabiob
fabiob

Reputation: 295

the solution is:

print(u'\U0001f61e')

apparently the capital U is needed to tell that it is an emoticon that it is going to be printed, which is identified by a 8-character-long string.

Upvotes: 1

Related Questions