Home >Backend Development >Python Tutorial >What are the python variable names?
Python needs to use identifiers to name variables. In fact, identifiers are symbols used to name variables, classes, and methods in the program (in simple terms, identifiers are legal names).
#Python language identifiers must start with a letter, an underscore (_), and can be followed by any number of letters, numbers, and underscores (_). The letters here are not limited to the 26 English letters, and can include Chinese characters, Japanese characters, etc.
Since Python 3 supports the UTF-8 character set, Python 3 identifiers can use characters from multiple languages that UTF-8 can represent. The Python language is case-sensitive, so abc and Abc are two different identifiers.
Python 2.x has poor support for Chinese. If you want to use Chinese characters or Chinese variables in a Python 2.x program, you need to add "#coding:utf-8" to the first line of the Python source program. ”, of course don’t forget to save the source file as UTF-8 character set.
When using identifiers, need to pay attention to the following rules:
Identifiers can be composed of letters, numbers, and underscores (_), and numbers cannot begin with them. .
Identifiers cannot be Python keywords, but can contain keywords.
Identifiers cannot contain spaces.
For exampleThe following variables, some are legal and some are illegal:
abc_xyz: legal.
HelloWorld: Legal.
abc: Legal.
xyz#abc: Illegal, "#" is not allowed in the identifier.
abc1: Legal.
1abc: Illegal, the identifier does not allow numbers to begin with.
The above is the detailed content of What are the python variable names?. For more information, please follow other related articles on the PHP Chinese website!