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

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

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

jpg

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

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

jpg

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.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值