0
Could someone explain how the output is 6?
def func(x): res = 0 for i in range(x): res += i return res print(func(4))
2 odpowiedzi
+ 6
0+1+2+3
+ 1
When range is used like this: range(x) it generates the interval of integers [0, x) {0 included, x excluded}. Therefore, calling func(4) adds the numbers in [0, 4) so
0+1+2+3=6.