samedi 25 février 2017

How do the logic operators work in an if statement with Python?

if "link?" or "Link?" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
        print ("Link String found " + comment.id)
        print(comment.body)
        #comment.reply("Here you go!")
        print ("Replied to comment ")
        #time.sleep(600)

When I run the code it skips through the first "link", or rather it runs the code inside the if statement whether or not "link?" is found in comment.body. I'm trying to run the code as:

if (a or b) and c and d

Where it's searching for either the string "link?" or the string "Link?" in the comment body. If either one is found, it will run the code in the for loop. It currently works if I have:

if "link?" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():

So I know that it's the "or" operator that is wrong. It's just that I'm used to coding with Java where operators can be held in brackets.

Aucun commentaire:

Enregistrer un commentaire