Use end within a function

0

I can not use end within the print function. I'm using version 2.7 of python.

Example:

for i in range(10):
     print("el numero es " + str(i), end=" ")

I need you not to make the line break and print it on the same line

    
asked by Santiago 14.02.2018 в 01:14
source

2 answers

0

There are many ways to accomplish what you are looking for. The easiest way is the following

>>> import sys
>>> for i in xrange(10):
...     sys.stdout.write("El numero es:" + str(i))
... iiiiiiiiii

Another way is using a backspace with "\ b"

>>> for i in xrange(10):
>>> print '\bi'
... iiiiiiiiii

If you have English skills at this question you can find and try several ways.

You let me know if you have any questions or problems.

    
answered by 14.02.2018 / 01:28
source
0

Another possibility is to bring the print from the future (although it is already present for a long time):

from __future__ import print_function

for i in range(10):
     print("el numero es " + str(i), end=" ")
    
answered by 14.02.2018 в 18:18