0

I am not able to understand how the final result is 6

def func(x): res = 0 for i in range(x): res += i return res print(func(4))

5th Sep 2016, 5:01 AM
Sujit Thonse
Sujit Thonse - avatar
1 ответ
+ 1
range(4) = 0 , 1 , 2 , 3 for i in range(x): res += i So it mean res is summary of range(4) = sum(0, 1, 2, 3) = 6
5th Sep 2016, 5:38 AM
beauty1234