Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use λ,φ,α,... in the jupyter notebook, just as in julia

As some of you probably know, you can use λ,φ,α,.., in any julia script. Couldnt this also be possible for python? I would use julia, but there are still some packages from python which I would have to wrap.

Best wishes

like image 875
varantir Avatar asked Sep 15 '25 21:09

varantir


1 Answers

Python 3 supports λ,φ,α and many other Unicode characters in identifiers (as mentioned by @jwodder). In jupyter notebook, you can access these characters by typing

\<character name><tab>

Example

\alpha<tab> = 1
# α = 1

Not all Unicode characters can be used as variable names, e.g. emojis:

>>> ♥ = "love"
  File "<ipython-input-29-97d253080b57>", line 1
    ♥ = "love"
    ^
SyntaxError: invalid character in identifier

However, letter-like characters are allowed, particularly in foreign languages:

>>> αγαπώ = "love"
>>> люблю = "love"
>>> 愛 = "love"

See also David Beazley's talk Mastering Python 3 I/O for more on practical uses of Unicode.

like image 173
pylang Avatar answered Sep 19 '25 10:09

pylang