python - 为什么 Python "is" 运算符对包含相同字符串的变量给出不同的结果
问题描述
当我试图比较包含相同字符串的两个变量的身份时,python 给了我不同的结果。
msg = "hello world"
new_msg = "hello world"
print( msg is new_msg )
> False
但,
msg = "hello_world"
new_msg = "hello_world"
print( msg is new_msg )
> True
解决方案
推荐阅读
- python - 机器学习中的步长和学习率有什么区别?
- r - 如何在 R 中使用 Inf/-Inf 预测数据?
- javascript - 如何在 2 列中制作手风琴(左侧内容链接到右侧)
- guidewire - 如何在 .pcf 文件中编写代码部分或方法?
- javascript - 未捕获的 SyntaxError:输入意外结束 - sid
- visual-studio - 有没有类似于 MSVS 的“#pragma GCC system_header”的东西?
- javascript - 加载模块脚本失败:服务器以“text/plain”的非 JavaScript MIME 类型响应
- c# - ASP.NET Core 应用程序不会在容器中启动
- windows - 如何在 Windows 中为某些目录使用替代名称?
- python - 对象在我的 pygame 代码中只移动一种方式,我该如何解决这个问题?