python tips

==比较内容相等性

is测试对象相等性

X=[1,2,3];
Y
=X[:];
print('X',X);
print('Y',Y);
print(X==Y);
print(X is Y);


X[
2]=2;
print('X',X);
print('Y',Y);

结果

X [1, 2, 3]
Y [1, 2, 3]
True
False
X [1, 2, 2]
Y [1, 2, 3]

原文地址:https://www.cnblogs.com/phoebus0501/p/1933232.html