+ 2

What do percentage signs do?

What does the percentage sign do in the example? I don't understand it evens=[i**2 for i in range(10) if i**2 % 2 == 0] print(evens)

8th Mar 2018, 11:57 AM
Samuel To
6 Respostas
+ 12
he is talking about % in python @Blizz //only started language till now try different modifications using -ve integers as operands for % operator
8th Mar 2018, 12:25 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 8
It is called the "Modulus". It returns the remainder of the division. Example :- 5 % 2 => 1 4 % 2 => 0 In the example you gave, it checks if the number is an even number. It does so by checking if the number when divided by 2 gives reminder 0.
8th Mar 2018, 12:09 PM
Nikhil
Nikhil - avatar
+ 4
it is modulus operator. for an example 38 % 2== 37 ÷ 2 and nearest number for 37 in 2 is 36. So 37 - 36 = 1 so the remainder is 1
8th Mar 2018, 12:08 PM
Blizz
Blizz - avatar
+ 3
It is the modulo operator and in probably all the languages, it helps get the remainder of a division operation. Eg : 15%2 = 1 (Since 15/2 is 7 with 1 as remainder) Now in your example, the sign checks for even numbers by verifying that when you divide the number by two, you get no remainder.
8th Mar 2018, 12:08 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
you talking in what language?
8th Mar 2018, 11:58 AM
Blizz
Blizz - avatar
+ 2
here remainder (i%2) is 0 that means only even number is acceptable,so I**2 for I in range (10) 0**2 = 0 2**2 = 4 4**2 = 16 .... ..... ans. is print (even) or output even numbers.
8th Mar 2018, 2:34 PM
📈SmileGoodHope📈
📈SmileGoodHope📈 - avatar