检查字符串是否包含子字符串,当子字符串实际为FAL时返回true

2024-09-28 21:59:51 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

但这必须返回假,但返回真

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

Tags: tohttpscomtrueyourifusewww
1条回答
网友
1楼 · 发布于 2024-09-28 21:59:51

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

如果您正在运行代码,它应该正确打印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

相关问题 更多 >