如何检查两个变量是否引用同一对象?

x = ['a', 'b', 'c']
y = x                 # x and y reference the same object
z = ['a', 'b', 'c']   # x and z reference different objects

最佳答案

这就是 is 的用途:如果x is yTrue是同一对象,则x返回y

10-08 04:07