`is` 和 `==` 之间的区别? [英] Difference between `is` and `==`?

查看:92
本文介绍了`is` 和 `==` 之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
Python '==' vs 'is' 比较字符串,'is' 有时会失败,为什么?

在 Python 中,这两个语句有什么区别:

In Python, what is the difference between these two statements:

如果 x 是odp":

如果 x == odp":

推荐答案

== 运算符测试是否相等

is 关键字测试对象身份;我们是否在谈论同一个对象.请注意,多个变量可能引用同一个对象.

The is keyword tests for object identity; whether we are talking about the same object. Note that multiple variables may refer to the same object.

这篇关于`is` 和 `==` 之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆