当前位置: 移动技术网 > IT编程>脚本编程>Python > Python可以用中文命名

Python可以用中文命名

2020年03月21日  | 移动技术网IT编程  | 我要评论

小么哥的老婆,格林兄弟下载,一枝春桥夕

python中文命名

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

环境

  1. python 3.7.3 x64
  2. win10

    现象

    python在命名的地方都是可以用中文命名
    如:
  3. 变量
    在git bash中的测试cmd测试

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

    作用

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

    原因

    python2并不支持非ascii码标识符. 于2008年12月发布的python3开始支持. 2008年! 也就是十多年前.

    创建于2007年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可以用中文命名变量吗?

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网