title: Python - one character from the old line is printed at the end of the new one in countdown animation
body: <p>I am creating a command line interface in python and I need to use a countdown and make it visible to the user, so I have coded this function below:</p>
  <pre><code>import sys
  from time import sleep
  
  def secondsCountdown():
      remainingSeconds = 10
  
      while (remainingSeconds &gt;= 0):  
          secondsString: str = &quot;[&quot; + str(remainingSeconds) + &quot; seconds]&quot;
  
          if (remainingSeconds &gt; 0):
              print(secondsString, end=&quot;\r&quot;) # print line and delete the previous one
              sleep(1)
          elif (remainingSeconds == 0):
              print(secondsString) # only print line
  
          remainingSeconds -= 1
  </code></pre>
  <p>the code itself works fine, but when the previous value is 'deleted' and the new one is printed, an extra square bracket is displayed in the new line at the end, like this example:</p>
  <pre><code>[9 seconds]] ## problem
  
  [9 seconds] ## expected result
  </code></pre>
  <p>I tried to insert '\n' at the end of the 'secondsString' string but somehow this causes the code to stop deleting the previous line. I really don't know how to fix it. I hope for your help.</p>
  <p>Thanks in advance.</p>