title: What is this "and" statement actually doing in the return?
body: <p>I am trying to get a better understanding of the following python code and why the author has used the "AND" statement in the return.</p>
  
  <pre><code>def valid_password(self, password):
          PASS_RE = re.compile(r'^.{6,128}$')
          return password and PASS_RE.match(password)
  </code></pre>
  
  <p>further down the code...</p>
  
  <pre><code>if not self.valid_password(self.password):
      params['error_password'] = "Please enter a valid password."
  </code></pre>
  
  <p>I've tried inspecting the resulting object that gets handed back to the caller, however I still don't entirely understand how it works.</p>
  
  <p>It seems like this returns the password back to the caller and a boolean of whether or not the password is valid, however I don't understand how the calling function can check the bool of an object? Is this something basic about Python that I've missed?</p>
  
  <p>There is another example of a similar usage next to this one however it uses the "or" statement which to me is even more confusing:</p>
  
  <pre><code>def valid_email(self, email):
      EMAIL_RE  = re.compile(r'^[\S]+@[\S]+\.[\S]+$')
      return not email or EMAIL_RE.match(email)
  </code></pre>
  
  <p>Any advice on exactly what is going on here would be greatly appreciated. The code works and does what you would expect it to do, validates the input against a regular expression and returns True or False, however I would really like to understand what it was written like this and not simply returning the bool.</p>