progress

Progress bar

def progress(percent=0, width=30):
    left = width * percent // 100
    right = width - left
    print('\r[', '#' * left, ' ' * right, ']',
          f' {percent:.0f}%',
          sep='', end='', flush=True)

print() all over yourself …

There are fancy progress bars for Python, but what if you are in a hurry or don’t want to install additional modules or libraries. if that is the case then you can use a little known option of print(), namely end=”\r”.

Here goes :

import time

for i in range(100): 
  time.sleep(0.01)
  print(f'counting : {i}   ', end="\r")                                                                                         

you would use the carriage return symbol to return the cursor to the beginning of the line after every print. Then the print will overwrite the previous string.

You may also put some spaces after the number because the number is left aligned.