python文件命名可以用中文吗-已经十多年了!你知道 Python 可以用中文命名变量吗?...

Python 3 本身支持中文命名类/方法/变量

任何额外的库和工具都不需要, 不需要, 不需要!重要的话三遍。Python 3 本身就可以正确运行下面的代码:

python文件命名可以用中文吗-已经十多年了!你知道 Python 可以用中文命名变量吗?...

补一句,不光是 Python3 支持中文命名哦,以后一个一个语言讲过来,九成九你用的编程语言也支持。

下面是一个 Python 实用小程序的代码片段:

python文件命名可以用中文吗-已经十多年了!你知道 Python 可以用中文命名变量吗?...

Python 3 为什么支持非英文命名标识符

Python 2 并不支持非 ASCII 码标识符。 2008年12月发布的 Python3 开始支持。2008年!也就是十多年前,现在还不知道的话,你就OUT大了。

创建于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.