+ 1
output of code (py)
def func(x): res = 0 for i in range(x): res += i return res print(func(4)) output of this code is 6 and please help me to understand why..
3 Answers
+ 1
What result did you want to get?
+ 1
You added all the integers in a range object to variable res.
range(4) = 0, 1, 2, 3
res = 0+1+2+3=6
res was returned as 6, and 6 was printed.



