Home  >  Article  >  Backend Development  >  Can Chinese characters be used as variable names in python3.x?

Can Chinese characters be used as variable names in python3.x?

angryTom
angryTomOriginal
2019-10-22 11:14:4918941browse

Can Chinese characters be used as variable names in python3.x?

Can I use Chinese as variable names in python3.x?

Yes.

No additional libraries or tools are required. Python3 itself can run the following code correctly:

Can Chinese characters be used as variable names in python3.x?

In addition, Python3 is not the only one that supports Chinese naming. I will talk about the languages ​​​​one by one in the future, and 99% of them are the programming you use. The language is also supported.

The following is a code snippet of a Python utility applet:

Can Chinese characters be used as variable names in python3.x?

##Why does Python3 support non-ASCII named identifiers

Python2 does not support non-ASCII code identifiers. Python3, which was released in December 2008, began to support it. 2008! That is more than ten years ago. If you don’t know it now, you are OUT.

Created in May 2007, the Python enhancement proposal PEP 3131 -- Supporting Non-ASCII Identifiers explains the reasons for supporting non-ASCII code named identifiers. The Rationale (Based) section begins with a clear meaning, pointing out that many Python Developers who are not familiar with English prefer to name classes/methods in their native language rather than using English translations that are often incorrect. For developers who use the same native language, identifiers named in their native language can improve code clarity and Maintainability.

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.

Recommendation:

《python tutorial》

The above is the detailed content of Can Chinese characters be used as variable names in python3.x?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Python average valueNext article:Python average value