How to add progress bar to “for i in range(…)” loop in Python

You can use the tqdm library to easily add a progress bar to your Python for i in range(...) loop:


from tqdm import tqdm

at the top of your script and then surround range(...) with tqdm(...). For example,

mysum = 0
for i in range(50):
    sum += i


mysum = 0
for i in tqdm(range(50)):
    mysum += i