unicode as valid naming symbols

Dave Angel davea at davea.name
Tue Mar 25 15:45:51 EDT 2014


 Mark H Harris <harrismh777 at gmail.com> Wrote in message:
> greetings, I would like to create a lamda as follows:
> 
> √ = lambda n: sqrt(n)
> 
> 
> On my keyboard mapping the "problem" character is alt-v which produces 
> the radical symbol. When trying to set the symbol as a name within the 
> name-space gives a syntax error:
> 
>  >>> from math import sqrt
>  >>>
>  >>> √ = lambda n: sqrt(n)
> SyntaxError: invalid character in identifier
>  >>>
>  >>>
> 
> however this works:
> 
>  >>>
>  >>> λ = lambda n: sqrt(n)
>  >>>
>  >>> λ(2)
> 1.4142135623730951
>  >>>
> 
>    The question is which unicode(s) are capable of being proper name 
> characters, and which ones are off-limits, and why?

See the official docs


 http://docs.python.org/3/reference/lexical_analysis.html#identifiers

There's also a method on str that'll tell you:  isidentifier (). 
 To see such methods,  use dir ("")

As for why, you can get a pretty good idea from the reference
 above, as it lists 12 unicode categories that can be used. You
 can also look at pep3131 and at Potsdam ' s site. Both links are
 on the above page. Letters, marks, connectors,  and numbers,  but
 not punctuation. 


-- 
DaveA




More information about the Python-list mailing list