0

I want to use Unicode variable names for writing some math code in Python.

I tried the following

# -*- coding: utf-8 -*-
α  = 1
β = 3
print α + β 

But I get the error

[~/Desktop]$ python fun.py
  File "fun.py", line 2
    α  = 1
    ^
SyntaxError: invalid syntax

How can I fix this?

4
  • 3
    Are you on Python 2 or Python 3? If Python 2, get Python 3. Commented Nov 16, 2018 at 22:26
  • @user2357112: does that print α + β not give enough of a hint to that? Commented Nov 16, 2018 at 22:28
  • In Python 2.7 you can have unicode characters but not unicode names. Commented Nov 16, 2018 at 22:30
  • @usr2564301: It gives a hint, but only a hint. The same problem could occur on Python 3 with invisible Unicode characters on the alpha line, and parsing wouldn't reach the print. Commented Nov 16, 2018 at 22:30

1 Answer 1

-2

I don't believe you can.. Special characters (with the exception of the underscore and the dollar sign) aren't allowed in variables

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.