python memory address

Python memory allocation:

  1. For int, str, float type as long as the value is the same, the memory address is the same

                      E.g: 

                   a1 = 2.0  id(a1) = 141300656
                   b = 2.0    id(b) =  141300656
               

       2. For data of type list, dict, set, tuple, although the value is the same, the memory address is different with different names

                   E.g:         

               list1 =[1,2,2]  id(list1) = 141357784
               list2 = [1,2,2]  id(list2) = 141
                 

     The difference between is and == is that is not only has the same value but also the memory address must be the same, and == as long as the value is the same.

Guess you like

Origin blog.csdn.net/xxy_yang/article/details/85262720