Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

python - Check if the string contains the substring returns true when its actually false

Is it a problem with my editor or what stupid mistake am I making ? Here is the screen-shot

enter image description here

This code returns true and it actually should

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

But this must return False but returns 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

works fine: First one returns True, second one returns False:

If you're running your code, it should correctly print true because the first set is True, and then prints nothing after that:

true

if both were True, you would see

true
true

See below:

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)    

Output:

True
False

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...