Get the App
SLTechnology News&Howtos  ›  Development  › 

How to resolve Python variable naming rules and define variables

Shulou Source: shulou.com Published: 2022-06-02 06:16:52 10月04日 Update

This article introduces how to parse Python variable naming rules and define variables, the content is very detailed, interested friends can refer to, hope to be helpful to you.

First, define variables

Grammar rules:

Variable name = value

The'='in the middle of the syntax rules that define variables does not mean an equal sign in mathematics, but rather an assignment in a programming language. Assignment: in fact, when the program is executed, it first calculates the value to the right of the equal sign ('='), and then assigns the value on the right to the variable name to the left of the equal sign.

Note: variable names are customized to meet the naming rules for identifiers.

II. Rules for defining variables

Identifier:

Variable naming convention-identifier naming convention is a unified specification for defining various names in Python. The specific specifications are as follows:

1. Consists of numbers, letters, and underscores

two。 Cannot start with a number

3. Python built-in keywords cannot be used

4. Strictly case-sensitive

The following is a list of common keywords, these keywords do not need to memorize, in the process of learning Python will naturally remember, do not use will not make mistakes

None True False and as break class continue def del elif else assert except finally for from if import in is lambda not or pass raise return try shile with.

Naming habits:

1. See the name and know the meaning

two。 Big hump: that is, the first letter of each word is capitalized, for example: UserName

3. Small hump: the first letter of the word after the second word is capitalized, e. G. userName

4. Underscore: for example: user_name

Such as:

UserName =''on how to parse Python variable naming rules and define variables to share here, I hope the above can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Variables rules keywords keywords letters identifiers identifiers underscores no content words right capital meaning numbers time more equal signs grammar humps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn Docker MariaDB macOS