在python3.x中可以使用中文作为变量名吗-Python教程

资源魔 43 0

正在python3.x中能够应用中文作为变量名吗

能够。

任何额定的库以及对象都没有需求。 Python3自身就能够正确运转上面的代码:

1.jpg

补一句, 没有光是Python3支持中文定名哦, 当前一个一个言语讲过去, 九成九你用的编程言语也支持.

上面是一个Python适用小顺序的代码片断:

2.jpg

Python3为何支持非ASCII码定名标识符

Python2其实不支持非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.

保举:《python教程》

以上就是正在python3.x中能够应用中文作为变量名吗的具体内容,更多请存眷资源魔其它相干文章!

标签: Python python教程 python编程 python使用问题 中文变量

抱歉,评论功能暂时关闭!