title: Understanding elegant prime number tester
body: <p>I'm new to Python and testing myself with some questions. One that came up was to test whether a user inputted number was prime or not. Easy enough, but one person came up with a single line of code as a solution. </p>
  
  <pre><code>
  import math
  
  num = int(input("Enter a number greater than 2 "))
  
  if sum([True if num%factor == 0 else False for factor in ([2] + list(range(3,int(math.sqrt(num)),2)))]):
    print("Number is composite")
  else:
    print("Number is prime")
  
  </code></pre>
  
  <p>I understand part of it: the <code>if</code> statement is True if (number/iterations) gives a remainder of 0, else False, where the only iterations that need to be checked are 2 -> sqrt(number) skipping all even numbers.</p>
  
  <p>However, I can't work out how to sum operator at the start of the if statement works. I assume it operates on the True(1)/False(0) statements, but how does this interaction play out and how does it affect the if/else statements?</p>