user10255809
user10255809

Reputation:

Why does range in Python increments by 1 in the loop when performing calculation?

My Y[], Y1[] both have range(0, 8736). When running the code below, why does the range extend by 1 to range(0, 8737)?

diff = []

for i in range(len(Y)):
    if(Y[i]==0):
        diff.append(1)
    if(Y1[i]==0):
        diff.append(1)
    else:
        var = Y[i] / Y1[i] 
        diff.append(var)

print(range(len(diff)))

Upvotes: 0

Views: 60

Answers (1)

Thomas Schillaci
Thomas Schillaci

Reputation: 2453

When i = 0 you append 1 twice, therefore len(diff) = len(Y) + 1 = len(Y1) + 1

Upvotes: 1

Related Questions