python怎样判断字符串相等

图片[1]-python怎样判断字符串相等-uusu优素-乐高,模型,3d打印,编程

python字符串如何判断相等

1.is来判断

groupName=params['groupName']##groupName的值是'url'
reqBody['dim']=groupName
print("reqBody_dim-SummaryListHandler",reqBody['dim'])
##('reqBody_dim-SummaryListHandler',u'url')
print("reqBody_dim_url-SummaryListHandler",('url'isreqBody['dim']))
##('reqBody_dim_url-SummaryListHandler',False)
ifgroupNameis'url':
打印如下,看到通过is判断是false
('reqBody_dim-SummaryListHandler',u'url')
('reqBody_dim_url-SummaryListHandler',False)

2.id 和 in

看到用in可以判断两个字符串相等

print("groupName:",groupName)
reqBody['dim']=groupName
print("reqBody_dim-SummaryListHandler",reqBody['dim'])
print("reqBody_dim_url_is-SummaryListHandler",('url'isgroupName))
print("reqBody_dim_url_id-SummaryListHandler",(id('url')==id(groupName)))
print("reqBody_dim_url_in-SummaryListHandler",('url'ingroupName))
('groupName:',u'url')
('reqBody_dim-SummaryListHandler',u'url')
('reqBody_dim_url_is-SummaryListHandler',False)
('reqBody_dim_url_id-SummaryListHandler',False)
('reqBody_dim_url_in-SummaryListHandler',True)
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容