100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Python可以用中文命名

Python可以用中文命名

时间:2023-06-21 10:15:33

相关推荐

Python可以用中文命名

Python中文命名

命名规则数字、字母、下划线

环境

python 3.7.3 x64win10

现象

Python在命名的地方都是可以用中文命名

如:

变量

中文下划线无法被识别打出中文下划线按退格键会不会被识别,会把前边一个字符删了
类、类属性、方法、函数

作用

都不用写注释,但是开发效率降低了点(来回切换输入法)

原因

Python2并不支持非ASCII码标识符. 于12月发布的Python3开始支持. ! 也就是十多年前.

创建于5月的Python增强提案PEP 3131 – Supporting Non-ASCII Identifiers阐述了支持非ASCII码命名标识符的缘由. Rationale (依据) 一节开篇明义, 指出很多Python开发者并不熟悉英语, 更希望用母语对类/方法进行命名, 而不是用经常有误的英文翻译. 对使用同样母语的开发者来说,用母语命名的标识符可以提高代码清晰度和可维护性.

Python code is written by many people in the world who are not familiar with the English language, or even well-acquainted with the Latin writing system. Such developers often desire to define classes and functions with names in their native languages, rather than having to come up with an (often incorrect) English translation of the concept they want to name.By using identifiers in their native language, code clarity and maintainability of the code among speakers of that language improves.

文献

已经十多年了! 你知道Python3可以用中文命名变量吗?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。