Little help


#1

hello. For me was really hard sometimes, I have been not understanding some lessons from passed several days, and I am on the list comprehension syntax lesson.

doubles_by_3 = [x * 2 for x in range(1, 6) if (x * 2) % 3 == 0]

# Complete the following line. Use the line above for help.
even_squares = [x ** 2 for x in range(1, 12) if x % 4 == 0]

print even_squares

result [16, 64] ( I really can not understand why)
I mean by that…

I understand if x %2 ==0 , I align (1 2 3 4 5 6 7 8 9 10 11) by square it is ( 1 4 9 16 25 36 49 64 81 100 121) from divided 2 is [4 16 36 64 100] , If x%4 ==0 from (1 4 9 16 25 36 49 64 81 100 121) , I thought same as divide 4 and for me result is [ 4 16 36 64 10]. I do not understand something in [x % _] == 0.


#2

% is the modulo operator, not the division operator (/)

do you understand how the modulo operator works?


#3

I do not understand. Can you explain little bit?


#4

the modulo operator calculates the remainder after division. How you wrote the code, if there is nothing left after division (the number is divisible by the divider) add it to list (if condition of list comprehension)


#5

Thanks so much, now I get understand.


#6

billguun

i dont understand it either


#7

the issue of OP (original poster) has been resolved, as such the topic will be closed

if you still have a question, make a new (linked) topic to ask your question, see guidelines


#8