Python range question

Asked 2 years ago, Updated 2 years ago, 90 views

def print_5xn(a):

A = int(len(a) / 5)
for i in range(A+1) :
    print(a[i * 5: i * 5 + 5])


 print_5xn("1234567898888")
 12345
 67898
 888

def print_5xn(a):

A = int(len(a) / 5)
for i in range(A) :
    print(a[i * 5: i * 5 + 5])


 print_5xn("1234567898888")
 12345
 67898

I thought changing A+1 to A would result in the same result, but I want to know why the result is different.

range

2022-09-20 15:37

1 Answers

See for yourself how the code works.

for i in range(3):
    print(i)

for i in range(4):
    print(i)


2022-09-20 15:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.