= = compares the values on both sides
Is compares the memory addresses on both sides to get memory addresses by ID ()
Small Data pools: The values we use are stored in small data pools for use by other data.
Small data pools are limited to numbers and strings:
Number of decimal pool ranges-5---256
String 1. Cannot have spaces;
2. The length cannot exceed 20 characters;
3. Cannot have special characters such as: @#$
1. ID () Get memory address
' Alex ' Print (ID (a)) # 36942544 memory address
2. = = Compare values on both sides
' Alex ' 'Alex'print(a = = b )=ten = tenprint (n= = [li1 = [n/a]print(= = = Li2) #True
3. Is compare memory address
3.1 List Dictionary tuple collection
#ListLi =[1,2,3]li2=[1,2,3]Print(Li isLI2)#False#Meta-groupTu = (A) TU1= (A)Print(TU isTU1)#False#DictionaryDic1 = {'name':'Alex'}dic= {'name':'Alex'}Print(Dic1 isDiC#False
Compare the above is#ListLi =[1,2,3]li2=[1,2,3]Print(Li = = li2)#True#Meta-groupTu = (A) TU1= (A)Print(Tu = = TU1)#True#DictionaryDic1 = {'name':'Alex'}dic= {'name':'Alex'}Print(Dic1 = = dic)#True
3.2 for the STR small data pool
String 1. Cannot have spaces;
2. The length cannot exceed 20 characters;
3. Cannot have special characters such as: @#$
A ='[email protected]'A1='[email protected]'Print(A isA1)#Falesa='a'*21b='a'*21Print(A isb#Falsea="AB"b="AB"Print(A isb#False But the result in Pycharm is true
3.3 Small Data pool for int
Number of decimal pool ranges-5---256
n =-6=-6 # out of range print is N1) #False =-5=-5print is N1) #True
n = 257
N1 = 257
Print (n is N1) #cmd中为False displayed as true in Pycharm
The difference between = = and is in Python