Python中文命名
命名規則數字、字母、下劃線
環境
- python 3.7.3 x64
- win10
現象
Python在命名的地方都是可以用中文命名
如:
- 變數


- 中文下劃線無法被識別
- 打出中文下劃線按退格鍵會不會被識別,會把前邊一個字符刪了
- 類、類屬性、方法、函式

作用
都不用寫注釋,但是開發效率降低了點(來回切換輸入法)
原因
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可以用中文命名變數嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/168991.html
標籤:Python
下一篇:7.機器學習之線性回歸演算法
