Caching mechanism variables

 Number caching mechanism of some variables

Action: save memory space, improve operating efficiency
 1. For integers, the same value within the range of positive infinity -5 ~ id consistent
var1 =. 5
var2 =. 5
var1 = -6
var2 = -6
Print (ID (var1), id (var2))


 2. For floating point number, the same as a non-negative value within the range consistent with id
var1 = -5.88
var2 = -5.88
Print (id (var1), id (var2))


 3. Boolean terms, the value of the same circumstances, id consistent
var1 = True
var2 = True
Print (ID (var1), id (var2))


 4. plurality In this configuration the real + imaginary numbers never the same (only when the number of virtual exceptions)
var1 =. 4 + 2J
var2 =. 4 + 2J
Print (ID (var1), ID (var2))
var1 =. 4J
var2 =. 4J
Print (id (var1), id ( var2))

 

5. empty string and tuple same situation, the same address
var1 = "you"
var2 = "you"
Print (ID (var1), ID (var2))

var1 = ()
var2 = ()
print(id(var1) ,id(var2))

 6. lists, tuples, dictionaries, no matter what set identifier id is different [empty tuples exception]
var1 = [l, 2,3]
var2 = [l, 2,3]
Print (id (var1), id ( var2))

 res = "I love you" * 3
Print (RES)

Guess you like

Origin www.cnblogs.com/weekz/p/11128294.html