How to make multiple prints on the same line in python 3? [duplicate]

-1

I want to know how to make prints appear on the same line using python 3. Example:

print('1')
print('2')
1
2

I wanted when python was to start number 2, number one was deleted and number 2 was on the same line as 1 was before.

I tried to do with a code made available in another question right here, but I did not get the expected result.

import sys
import time

for x in range(11):
  print("{}%".format (x))
  sys.stdout.write("3[F")
  time.sleep(0.1)
    
asked by anonymous 05.11.2018 / 16:57

1 answer

4
Python 3 automatically puts a line break at the end of print , but you can override it with whatever you want it to be by adding the end :

print('1', end='') 
print('2')

In this way the print will end with an empty string instead of a line break and the second print will be rendered shortly afterwards.

    
05.11.2018 / 17:02