+ 1
i//2 == 20 then i = 40 ,i//2 = 40/2 = 20 Why the answer print(a) = [20] is incorrect ?
a = [i//2 for i in range(50) if i//2 == 20] ; print(a)
4 Respostas
+ 1
Remember : // is the floor division operator.
40 // 2 = 20
41 // 2 = 20
So 'a' will contain two times '20'.
+ 3
there are two numbers(40 and 41) which will give 20 as the quotient within the range you specified. So, 20 is returned 2 times in the list(a)
+ 1
Théophile I know that floor division operator returns quotient but I couldn't understand why and how a contains two times '20' ?