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

13th Oct 2020, 5:09 AM
Rajan K
Rajan K - avatar
4 Respuestas
+ 1
Remember : // is the floor division operator. 40 // 2 = 20 41 // 2 = 20 So 'a' will contain two times '20'.
13th Oct 2020, 5:16 AM
Théophile
Théophile - avatar
+ 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)
13th Oct 2020, 8:18 AM
Ren
+ 3
Ren and Théophile Thankyou for clearing my doubt
13th Oct 2020, 9:27 AM
Rajan K
Rajan K - avatar
+ 1
Théophile I know that floor division operator returns quotient but I couldn't understand why and how a contains two times '20' ?
13th Oct 2020, 7:48 AM
Rajan K
Rajan K - avatar