码迷,mamicode.com
首页 > 编程语言 > 详细

Python-in is == 区别

时间:2018-05-25 01:45:09      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:key   qiniu   print   ini   bcd   python   one   字典   str   

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 == 区别

标签:key   qiniu   print   ini   bcd   python   one   字典   str   

原文地址:https://www.cnblogs.com/2bjiujiu/p/9085918.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!