Home Backend Development Python Tutorial Detailed explanation of examples of variables and constants in Python

Detailed explanation of examples of variables and constants in Python

Jul 26, 2017 am 09:40 AM
python Base constant

Let’s take a look at Python’s variables and constants today:

First of all, let’s talk about the process of interpreter executing Python: python3 C:\test. py

1. Start the python interpreter (in memory)

2. Read the contents of C:\test.py from the hard disk into the memory (This step is the same as the text editor)

3. Execute the code read into the memory

If you want to save the code permanently, You must use the file method
If you want to debug the code, you must use the interactive method

Variables What is it?

Change: change, the core lies in change Quantity: measurement, measurement, expression is a state

Definition of variables

ps:

level = 1

level: variable name =: assignment operator 1: value

Definition rules:

The variable name can only be any combination of letters, numbers or underscores

The first character of the variable name cannot be a number

The following keywords cannot be declared as variable names

['and', 'as', 'assert', 'break', 'class', 'continue' , 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', ' in', 'is', 'lambda', 'not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield' ]

python has a resource recycling mechanism

ps:

name='lln' #'lln'The reference count of this value +1
name='llh' #'llh'The reference count of this value +1,' The reference count of lln' this value is -1
The reference count of the value or the variable name bound to the value is 0, and the python interpreter will periodically recycle them to free up space.

is is the comparison id == is the comparison value

The three important components of variable definition:

id address
type type
value value

ps:

Constant

Unchanging quantity
There is no special way to define constants in Python. Capitalized variable names are usually used to represent constants.
It’s just a reminder.
ps :

LLN_body=50 (The essence is that the variable can be changed)


Little knowledge points: Definition The method usually has camel case and underline

ps:

LlnOldboy = <span class="hljs-number">50</span>

lln_oldboy = 50

## Comment rules:

 1 #单行注释 2 #注释可以是英文和中文不能使用拼音 3  4 """ 5 多行注释 6 第一种方式 7 """ 8  9 '''10 多行注释11 第二种方式12 '''
Copy after login

The above is the detailed content of Detailed explanation of examples of variables and constants in Python. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

What are the advantages and disadvantages of templating? What are the advantages and disadvantages of templating? May 08, 2024 pm 03:51 PM

What are the advantages and disadvantages of templating?

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Google AI announces Gemini 1.5 Pro and Gemma 2 for developers Jul 01, 2024 am 07:22 AM

Google AI announces Gemini 1.5 Pro and Gemma 2 for developers

How to download deepseek Xiaomi How to download deepseek Xiaomi Feb 19, 2025 pm 05:27 PM

How to download deepseek Xiaomi

How do you ask him deepseek How do you ask him deepseek Feb 19, 2025 pm 04:42 PM

How do you ask him deepseek

How to save the evaluate function How to save the evaluate function May 07, 2024 am 01:09 AM

How to save the evaluate function

What software is NET40? What software is NET40? May 10, 2024 am 01:12 AM

What software is NET40?

How to search deepseek How to search deepseek Feb 19, 2025 pm 05:18 PM

How to search deepseek

What language is the browser plug-in written in? What language is the browser plug-in written in? May 08, 2024 pm 09:36 PM

What language is the browser plug-in written in?

See all articles