DEV Community

Cover image for Printing emojisπŸ˜πŸŽ‰πŸ˜›πŸ˜›πŸ˜ in python 🐍🐍
Jhohannes
Jhohannes

Posted on

6 1

Printing emojisπŸ˜πŸŽ‰πŸ˜›πŸ˜›πŸ˜ in python 🐍🐍

Have you ever thought of inserting emojis into your python program? Well, if you haven't, you should start thinking of inserting one into some of your mini projects to make it fun😜.
Emojis are now everywhere, even in programming now.
In python now, there are three ways you could insert an emoji.

  • You could use unicodes
  • The Common Locale Data Repository(CLDR) names
  • The emoji module

Using the unicodes

Every emoji we use when chatting all have unicodes and we can use these unicodes in python to output these same emoji.
Codes

# face with tears of joy
print("\U0001f602")

# face with tongue
print("\U0001f61b")
Enter fullscreen mode Exit fullscreen mode

Output
πŸ˜‚
πŸ˜›

For the full emoji list, visit Link
Replace the "+" with "000". So "U+1F602" becomes "U0001F602".

Using CLDR names

Emojis also have CLDR short names. All the short names are provided in the link above.

Code

# face with tears of joy
print("\N{face with tears of joy}")

# face with tongue
print("\N{face with tongue}")
Enter fullscreen mode Exit fullscreen mode

Output
πŸ˜‚
πŸ˜›

Using the emoji module

To install the module, run pip install emoji in your terminal.
We will use the CLDR short names here by using the emojize() function. All spaces the the CLDR short names would be replaced by an underscore.
Code

# Import the module
import emoji

print(emoji.emojize("Python is :thumbs_up:")
print(emoji.emojize("I :red_heart: python")
Enter fullscreen mode Exit fullscreen mode

Output
Python is πŸ‘
I ❀️ python

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

πŸ‘₯ Ideal for solo developers, teams, and cross-company projects

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay