the variables of python

来源:互联网 发布:部落冲突黑油钻井数据 编辑:程序博客网 时间:2024/05/16 00:37

This part is easy relatively , if have learned or used javascript ,then you will feel that is very easy . Python's variable is  a type of weak type.

Then I will give several examples to explain this question.

no.1:

#don't delimit the type  at first

a = 1 

a = "abc"

a = 1.88


no.2:

#in one program,the one name can use more than once

var = one

var = "two"

as shown above,in the  first one, the "var" is a reference and the "one"  is a object,in the second , the "var" became a reference of "\'two\'",and  over a perid of time , the first "var" will be deallocated(release).

let's see the simple examples as follows:

>>>a = 1

>>>id(a)

xxxxxx36

>>>a=2

>>>id(2)

xxxxxx12

as shown above, the address is different,so the data is the main and the name is a tag.

>>> a =1

>>>id(a)

XXXXXX50

>>>b=1

>>>id(b)

XXXXXX50

as shown above, the address is equally , then the data  have two tags.


I  think the two precautions is important ,and if you have others question to add ,I will thanks you very much!




0 0