Python3 变量名中接受哪些 Unicode 符号? [英] What Unicode symbols are accepted in Python3 variable names?
问题描述
我想在我的 Python3 脚本中使用更多种类的 Unicode 符号作为变量名.在 Python3 变量名中可以使用哪些字符?
I want to use a larger variety of Unicode symbols for variable names in my Python3 scripts. What characters are acceptable to use in Python3 variable names?
更新:我最近开始使用 Unicode 符号(例如希腊和亚洲符号)进行代码混淆.
UPDATE: I recently started using Unicode symbols (such as Greek and Asian symbols) for code obfuscation.
推荐答案
根据 PEP 3131,标识符的第一个字符需要属于ID_Start
,其余为ID_Continue
,定义如下:
According to PEP 3131, the first character of an identifier needs to belong to ID_Start
, the rest to ID_Continue
, defined as follows:
ID_Start
被定义为所有具有以下特征之一的字符类别 大写字母 (Lu)、小写字母 (Ll)、标题字母 (Lt)、修饰字母 (Lm)、其他字母 (Lo)、字母数字 (Nl)、下划线和带有Other_ID_Start 属性.XID_Start 然后关闭这个集合规范化,通过删除所有 NFKC 规范化的字符不再是 ID_Start ID_Continue*
形式.
ID_Start
is defined as all characters having one of the general categories uppercase letters (Lu), lowercase letters (Ll), titlecase letters (Lt), modifier letters (Lm), other letters (Lo), letter numbers (Nl), the underscore, and characters carrying the Other_ID_Start property. XID_Start then closes this set under normalization, by removing all characters whose NFKC normalization is not of the formID_Start ID_Continue*
anymore.
ID_Continue
定义为 ID_Start
中的所有字符,加上非间距标记 (Mn)、间距组合标记 (Mc)、十进制数(Nd)、连接符标点符号 (Pc) 和带有Other_ID_Continue 属性.再次,XID_Continue
关闭这个集合在 NFKC 规范化下;它还添加了 U+00B7
以支持加泰罗尼亚语.
ID_Continue
is defined as all characters in ID_Start
, plus
nonspacing marks (Mn), spacing combining marks (Mc), decimal number
(Nd), connector punctuations (Pc), and characters carryig the
Other_ID_Continue property. Again, XID_Continue
closes this set
under NFKC-normalization; it also adds U+00B7
to support Catalan.
这是一个很长的列表(目前大约 120.000 个字符) - 幸运的是 GitHub 上有一个有用的项目包含列表和生成它的脚本.
That's a long list (currently around 120.000 characters) - fortunately there is a helpful project on GitHub that contains the list and a script to generate it.
这篇关于Python3 变量名中接受哪些 Unicode 符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!