python判断字符串相等

The operator a is b returns True if a and b are bound to the same object, otherwise False. When you create two empty lists you get two different objects, so is returns False (and therefore is notreturns True).

is is the identity comparison. #比较引用是否相同

== is the equality comparison. #比较内容是否相同


python中新建变量时,并不需要指定类型,因为每个变量实际上存储的是一个引用,就是指向一个对象实体的指针。

is 判断的就是这个指针的值是否相同,如果相同则表示两个变量指向同一个对象实体。

而==则比较它们的内容是否相同,这一点与Java中的String不同。


猜你喜欢

转载自blog.csdn.net/Bill_Marz/article/details/85220604