Python: Emoji Module

Featured Img Emoji Module

Hey, there fellow learner! Today we will be learning something fun! We will be taking a look at the emoji module in python.

So let’s begin!

Introduction to emojis

In today’s world, people communicate their emotions through emojis rather than typing out long passages. Emojis have become a major part of our day-to-day communication with each other.

Today in this tutorial I will be teaching you how to print emojis on your own using simple code lines and the emoji the module of python.

Printing your own emojis with the emoji module

We first start by importing the emoji module. If any error occurs while importing we need to install the module using the pip command on the command prompt.

To print an emoji on the screen, we will be using the emojize() function which takes the name of the emoji enclosed within the colon (:) as a parameter.

The function automatically returns the emoji as a result.

If for some reason you don’t know the text for a particular emoji, we can use the demojize() function and pass the emoji as a parameter.

The code for the same is shown below:

import emoji
print(emoji.emojize("Hello there friend! :grinning_face_with_big_eyes:"))

The output of the code is shown below. You can see the first function converted emoji to text while the second function converted text to emoji.

Hello there friend! 😃

What are Unicodes?

Instead of using long texts for emojis, we can directly use the unicode for an emoji. Every emoji has a unique Unicode corresponding to the emoji.

You can get the Unicode for any emoji from this website. All we need to do is replace the + in the Unicode with 000 to get the correct Unicode.

Printing emoji using Unicode is very simple which doesn’t require any function other than the print statement along with a backslash (\) before the Unicode to print the emoji.

The code below displays printing a bunch of emojis together with the help of unicodes.

print("\U0001F680 \U0001F649 \U0001F698 \U0001F6C1")

The output of the code above is as follows:

🚀 🙉 🚘 🛁


So today we learned to print emojis in our sentences on our own. You can build fun text-based games using the fun emojis in our texts! Hope you liked the tutorial!

Keep reading and learning! Thank you.