Python-in is == 区别
Posted 北门吹雪
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python-in is == 区别相关的知识,希望对你有一定的参考价值。
in
判断单个元素是否在序列中, 对字典来说只能判断key
print("ab" in "abcdefg") print("abc" in ["abc", "ac"]) print([1, 2] in [[1, 2], "3"]) print("abc" in {"abc": 33}) print(33 in {"abc": 33})
is
身份判断,判断内存地址是否相等
nameOne = "BeiMenChuiXue" nameTwo = "QiNiuYun" nameThree = "QiNiuYun" print(nameOne is nameTwo, id(nameOne), id(nameTwo)) print(nameTwo is nameThree, id(nameTwo), id(nameThree))
==
判断值是否相等
nameOne = "BeiMenChuiXue" nameTwo = "QiNiuYun" nameThree = "QiNiuYun" print(nameOne == nameTwo) print(nameTwo == nameThree)
相同点
in is == 返回都是bool类型
以上是关于Python-in is == 区别的主要内容,如果未能解决你的问题,请参考以下文章
add application window with unknown token XXX Unable to add window;is your activity is running?(代码片段
Error: Python executable “H:devpython3.10python.EXE“ is v3.10.0, which is not supported by gyp.(代码片段
Kotlin学习之旅解决错误:kotlin.NotImplementedError: An operation is not implemented: Not yet implemented(代码片段
ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段
[未解决问题记录]python asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed')(代码片段
项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde(代码片段