title: printf-style string formatting with boolean condition in brackets string%d % (i condition)
body: <p>I can't understand how this condition behind the % works</p>
  
  <pre><code>for i in range(1,6): 
       print "pet%d" % (i == 1 and 2 or 4)
  </code></pre>
  
  <p>this part <code>(i == 1 and 2 or 4)</code> is what I cant understand. As far as I understand it does the same as a </p>
  
  <pre><code>if i == 1: 
      i = 2 
  else: 
      i = 4
  </code></pre>
  
  <p>but how does the <code>(i == 1 and 2 or 4)</code> work especially with the %d % i formatting?</p>