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

零下一度
零下一度Original
2017-07-26 09:40:281847browse

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

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