Using Emoji in Python

Programming is much more than just printing “Hello World!”

Adwiteeya Reyna
thinkingdatastructures
2 min readJun 29, 2020

--

Programming is fun and much more than just printing “ Hello World!” and number series. We can print emojis and get our hands dirty as much as we want. Thanks to the preferred installer program or pip, the one destination solution to all python problems! We can print emojis in three ways:

  • Unicodes
  • CLDR (Common Locale Data Repository) names
  • emoji module

Unicodes

You can get an entire list of Emojis Unicodes from here.

Every emoji has a Unicode associated with it. It starts with “U” followed by three zeroes (which is abbreviated by a +) and is 9 characters long. eg. “U0001F603”, “U0001F600” etc. In a nutshell, when you see something like this U+1F916, just replace “+” with “000”. While giving these Unicode as input, we need to prefix it by “\”.

input:

output:

Using CLDR

As every emoji is associated with a Unicode, in a similar manner, every emoji comes with a short name which can also be used to print them.

input:

output:

Using emoji module

Check this cheat sheet for an entire list of the emoji module names.

An alternative of the above two methods is using the emoji modules in order to print emojis. This requires the installation of emoji pip package:

The emojize() function requires the CLDR short name to be passed in it as the parameter. It then returns the corresponding emoji. One important thing to keep in mind is to replace every space with an underscore in the CLDR name string

input:

output:

--

--