Python可以用中文命名


Python中文命名

命名規則數字、字母、下划線

環境

  1. python 3.7.3 x64
  2. win10

現象

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

  1. 變量
    在git bash中的測試cmd測試
  1. 中文下划線無法被識別
  2. 打出中文下划線按退格鍵會不會被識別,會把前邊一個字符刪了
  1. 類、類屬性、方法、函數
    中文類名、函數名、屬性、方法名

作用

都不用寫注釋,但是開發效率降低了點(來回切換輸入法)

原因

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可以用中文命名變量嗎?


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM