March 2nd, 2013, 08:20 PM
Would wider spacing help you see?
m = re.search("play",phrase) and re.search("music",phrase)
The result of a python expression involving `and' and `or' logical tests is the last object python needed to evaluate to resolve the condition. Python evaluates from left to right, and obeying parentheses.
Thus 131 is the result of
131 or 'Our cat Zippy'
Try it in the interpreter!
In your case
re.search("play",phrase) and re.search("music",phrase)
the search for 'play' succeeded so the match object tested True, so python evaluated
Since there's nothing left to evaluate python returns the object that determined the outcome of the `and' expression and assigns it to m.
[/code] are essential for python code!
Last edited by b49P23TIvg : March 2nd, 2013 at 08:22 PM.