jeudi 22 décembre 2016

"In" Check not working in if Statement [duplicate]

This question already has an answer here:

I was doing some basic string manipulation and i came across something very interesting and confusing :

str= "HELLO WORLD"
x="LL"

t = x in str
print t

if x in str == True:
    print "TRUE"

When it's run, it currently only prints True on one occasion, on the first print statement. One would think that both would print as logically and almost syntactically they are the same yet one does not. I do not understand the reasoning behind this, especially given how Python is supposed to be intuitive.

Help would be much appreciated.

Thank you.

Aucun commentaire:

Enregistrer un commentaire