Hi wonderful developer, can you explain how we get the answer?

lst = [i*i for i in range(5)]
print(lst)
# [0, 1, 4, 9, 16]
  I got this as a result. I'm confused how it's working. 0 * 0 = 0 then rest of them will be 0 as 0 * 2 = 2 ... 

#python #project-feedback

The code says i * i
Then how do you believe that this will ever be 0 * 2???

Don’t you think that the computer will evaluate i as i each time?

I actually didn’t understand how it work, If you don’t mind just give me a short brief of how’s working. Appericate your time. Thanks hBar

i*i will square the value of i
The value of i comes from the statement for i in range(5) which will give i the value of 0 to 4)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.