Home Backend Development Python Tutorial What is the python variable name?

What is the python variable name?

Jul 06, 2019 am 11:09 AM
python variables

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

See all articles