Today I learned that you can use emojis as variable names in Python if you use pythonji
.
No! At the time of writing, emojis are not valid Python identifiers. This means that this code fails:
>>> π = "hamburguer" # SyntaxError
However, if you install the package
pythonji
,
you will be able to run code like that!
Installing pythonji
is as easy as python -m pip install pythonji
!
With pythonji
installed, we can run programs that make use of emojis!
Here's a little program I wrote:
import enum
class π½(enum.Enum):
π = "hamburguer"
π = "pizza"
π
= "tomato"
π₯ = "carrot"
class π§:
def __init__(π€³, ππ):
π€³.ππ = ππ
def π½(π€³, π):
if π in π€³.ππ:
return "Yummi!"
else:
return "Ok, I'll eat that."
π¨ = π§([π½.π, π½.π₯])
print(π¨.π½(π½.π))
print(π¨.π½(π½.π
))
Save it to the file foo.π
(yes, the extension really is π!).
Now, run it with pythonji foo.π
and this is the output:
> pythonji foo.π
Yummi!
Ok, I'll eat that.
Amazing, right? π
That's it for now! Stay tuned and I'll see you around!
+35 chapters. +400 pages. Hundreds of examples. Over 30,000 readers!
My book βPydon'tsβ teaches you how to write elegant, expressive, and Pythonic code, to help you become a better developer. >>> Download it here ππ.