检查字符串是否包含子字符串,但实际上是否为假

时间:2019-01-25 13:42:58

标签: python python-3.x

我的编辑器有问题还是我犯了什么愚蠢的错误?这是屏幕截图

enter image description here

此代码返回true,实际上应该

a = "https://www.reddit.com/comments/ado0ym/use_reddit_coins_to_award_gold_to_your_favorite/"
b = "use_reddit_coins_to_award_gold_to_your_favorite"

if b in a:
    print("true")

# Results return true

但这必须返回False但返回True

a = "https: // www.reddit.com/comments/ado0ym/"
b = "use_reddit_coins_to_award_gold_to_your_favorite"

if b in a:
    print("true")

# Results return true

1 个答案:

答案 0 :(得分:3)

工作正常:第一个返回True,第二个返回False:

如果您正在运行代码,则应该正确打印true,因为第一组为True,然后再打印任何内容:

true

如果两个都是True,您会看到的

true
true

参见下文:

a = "https://www.reddit.com/comments/ado0ym/use_reddit_coins_to_award_gold_to_your_favorite/"
b = "use_reddit_coins_to_award_gold_to_your_favorite"

print (b in a)



a = "https: // www.reddit.com/comments/ado0ym/"
b = "use_reddit_coins_to_award_gold_to_your_favorite"

print (b in a)    

输出:

True
False