Home > Backend Development > Python Tutorial > What are the python variable names?

What are the python variable names?

anonymity
Release: 2019-06-14 09:50:24
Original
32148 people have browsed it

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).

What are the python variable 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template