How to set and check boolean flag in python

I am trying to do something like this using boolean:

/* ... other stuff */ loggedDocument = false for line in inFile: if (line.find( /*something*/ ) != -1): println("FOUND DOCUMENT: %s" % line) loggedDocument = true if (loggedDocument == false): /* do something else */ 

But I keep getting invalid syntax errors. I googled but could not find a simple logical example, any ideas?

+7
source share
2 answers

You are looking for True and False (pay attention to capitals). Also, a more Pythonic way of writing the last line is if not loggedDocument instead of if loggedDocument == False . Edit: And BTW, println not Python a built-in Python function; are you looking for print() ?

+16
source

Booleans are spelled True and False .

Make sure you have spaces.

And remove the brackets after if , they are not needed.

+5
source