二十五岁时我们都一样愚蠢、多愁善感,喜欢故弄玄虚,可如果不那样的话,五十岁时也就不会如此明智。
标题:Python3 id运算符
Python3 id运算符
#!/usr/bin/python3 a = 20 b = 20 print ('Line 1','a=',a,':',id(a), 'b=',b,':',id(b)) if ( a is b ): print ("Line 2 - a and b have same identity") else: print ("Line 2 - a and b do not have same identity") if ( id(a) == id(b) ): print ("Line 3 - a and b have same identity") else: print ("Line 3 - a and b do not have same identity") b = 30 print ('Line 4','a=',a,':',id(a), 'b=',b,':',id(b)) if ( a is not b ): print ("Line 5 - a and b do not have same identity") else: print ("Line 5 - a and b have same identity")