Comprehending comprehensions


#1



No error message, the code works perfectly.
These numbers are displayed [3, 5, 6, 9, 10, 12, 15]


I cannot understand that this code works, because x % 3 or x % 5 is never going to be equal to 0.
3 % 3 == 1 ; 6 % 3 == 2.

Therefore, how can it be the right code to create a list that contains only numbers divisible by 3 or 5 ??


threes_and_fives = [x for x in range(1, 16) if x % 3 == 0 or x % 5 == 0]
print threes_and_fives


#2

the % is the modulo operator which gives you the remainder, you seem to confuse it with the division operator (/)


#3

Indeed, I did mix up both operators. It makes perfect sense now. Thanks again!


#4