知行编程网知行编程网  2022-10-24 20:30 知行编程网 隐藏边栏  6 
文章评分 0 次,平均分 0.0
导语: 本文主要介绍了关于python怎样判断字符串相等的相关知识,包括python字符串比较相等,以及python字符串判断相等这些编程知识,希望对大家有参考作用。

如何在python中判断字符串是否相等

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' is reqBody['dim'])) 
            ## ('reqBody_dim_url-SummaryListHandler', False)
            if groupName is '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' is groupName))
print("reqBody_dim_url_id-SummaryListHandler", (id('url')==id(groupName)))
print("reqBody_dim_url_in-SummaryListHandler", ('url' in groupName))


('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)

本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

知行编程网
知行编程网 关注:1    粉丝:1
这个人很懒,什么都没写
扫一扫二维码分享