+ 1

% Operator

evens=[i**2 for i in range(10) if i**2 % 2 == 0] print(evens) What is the % 2 == 0 saying in the above list comprehension. Please give me an actual numeric example.

23rd Apr 2018, 5:31 AM
Troy Kelley
Troy Kelley - avatar
3 Respuestas
+ 6
% (Modulus) almost same with / (division). The difference is when 10 / 2 = 5 but when 10 % 2 = 0 Because it doesnt remains anything... i'll just give some example... 100 % 5 = 0 ✔ because it doesnt remains anything... 20 % 4 = 2 ✔ because its only remain 2... 7 % 4 = 3 ✔ because its only remain 3...
23rd Apr 2018, 7:04 AM
ZΛRTHΛИ
ZΛRTHΛИ - avatar
+ 1
It means only even numbers are accepted. All even numbers are divided by 2. If we divide a number by 2 and there is no remainder ,then it expressed by number % 2 = 0. Modulus sign ( % ) used to determine remainder. 4%2 = 0 16%2 = 0 5%2 =1 [ remainder 1]
23rd Apr 2018, 6:35 AM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar
+ 1
Thank you everyone for your help! It’s a lot clearer now!
25th Apr 2018, 4:15 PM
Troy Kelley
Troy Kelley - avatar