+ 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)

6 ответов

+ 12

he is talking about % in python @Blizz
//only started language till now
try different modifications using -ve integers as operands for % operator

+ 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.

+ 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

+ 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.

+ 2

you talking in what language?

+ 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.