Home  >  Article  >  Backend Development  >  What is the python variable name?

What is the python variable name?

藏色散人
藏色散人Original
2019-07-06 11:09:0917303browse

What is the python variable name?

1. What is a variable?

The variable name is only defined the first time it appears (the variable name appears again, not to define the variable, but to use it directly Previously defined variables)

2. Definition of variables

In python, each variable must be assigned a value before use. The variable will not be created until the variable is assigned a value

The equal sign (=) is used to assign values ​​to variables

=The left side is a variable name

=The right side is the value stored in the variable

Variable name = value

After the variable is defined, you can use it directly later

The naming of the variable

1. Identifiers and keywords

Identifier

The identifier is the variable name defined by the programmer. The function name

The name needs to have a well-known effect

The identifier can be composed of letters , composed of underscores and numbers

cannot start with a number

cannot have the same name as a keyword

Keyword

The keyword is Identifiers already used within Python

Keywords have special functions and meanings

Developers are not allowed to define identifiers with the same name as keywords

Through the following The command can view the keywords in python

The import keyword can import a tool package

Different tool packages in python provide different tools

2. Variables Naming rules

Naming rules can be regarded as a convention, there is no absolute or mandatory

The purpose is to increase the recognition and readability of the code

Note: python The identifiers in are case-sensitive

When defining variables, in order to ensure the code format, a space should be reserved on the left and right sides of =

In python, if the variable name needs to be composed of two It consists of one or more words and can be named in the following way (commonly used in python)

Use lowercase letters for each word

Use _underscores to connect words between words

For example: first_name, last_name….

Camel case naming method: (commonly used naming methods in other languages)

When the variable name is composed of two or more words, you can also use the camel case command Fa Lai Naming

Little camel case naming method

The first word starts with a lowercase letter, and the first letter of subsequent words is capitalized

firstName lastName

Big camel case nomenclature

The first letter of each word is capitalized

FirstName LastName

Related recommendations: "PythonTutorial

The above is the detailed content of What is the python variable name?. 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