Python中变量的属性以及判断方法
在Python中,创建一个变量会给这个变量分配三种属性:
id ,代表该变量在内存中的地址;
type,代表该变量的类型;
value,该变量的值;
>>> x=10 >>> id(x) 1551917568 >>> y=10 >>> id(y) 1551917568 >>> x is y True >>> x==y True >>> x=100 >>> y=100 >>> id(x) 1551920448 >>> id(y) 1551920448 >>> x=200 >>> y=200 >>> id(x) 1551923648 >>> id(y) 1551923648 >>> x is y True >>> x=255 >>> y=255 >>> x is y True >>> x=256 >>> y=256 >>> x is y True >>> x=257 >>> y=257 >>> x is y False >>> id(x) 2075040894800 >>> id(y) 2075040894768 >>>
当整形变量大于256的时候,内存地址就不一样了。
浙公网安备 33010602011771号