ID (object)
function: returns the "Social Security Number" of the object, unique and unchanging, but the same ID value may appear during a non-coincident life cycle. The object mentioned here should refer specifically to objects of compound types (such as classes, lists, etc.), and for strings, integers, and so on, the ID of the variable changes with the value.
1 classObj ():2 def __init__(self,arg):3self.x=Arg4 if __name__=='__main__': 5 6Obj=obj (1) 7 PrintID (obj)#327544328obj.x=29 PrintID (obj)#32754432Ten Ones="ABC" A PrintID (s)#140190448953184 -s="BCD" - PrintID (s)#32809848 the -X=1 - PrintID (x)#15760488 -x=2 + PrintID (x)#15760464
Note:
To determine if two objects are equal, this is the ID value
The difference between IS and = = is that it is an in- memory comparison, and = = is a comparison of values
Python function ID ()