美文网首页
python is 和 ==

python is 和 ==

作者: 拉普不再拉丝 | 来源:发表于2018-08-21 16:35 被阅读0次

牛客网华为机试在线训练————计算字符个数

程序如下:

str0 = input()

str1 = input()

str0 = str0.lower()

str1 = str1.lower()

count = 0

for i in str0:

    if i == str1:

        count = count + 1

print(count)

在判断字符相等时,i ==str1时,遇到问题,本来使用is进行判断,后来经过查询,得知:

is 是判断两个变量引用的是否为同一个值:

==是判断两个变量的值是否相等。

相关文章

网友评论

      本文标题:python is 和 ==

      本文链接:https://www.haomeiwen.com/subject/fmejiftx.html