How can I make a print in a for loop and it appear without line breaks? - Python

0

I would like to know how I can make a print in a for loop without the line breaks. In python Thank you very much

    
asked by Abel Gallardo Puig 22.05.2018 в 18:07
source

2 answers

2

The answer depends on the version of python you are using. If you are using python2 you have to put a comma at the end of the impression:

print "tu mensaje",

Instead, in python3 you would have to set the default parameter "end" to an empty string or a space:

print("tu mensaje", end='')
    
answered by 22.05.2018 в 18:11
1

If you are using Python 3.x, it will be as simple as modifying the 'end' parameter, which by default is a line break '\ n'

print("Mi mensaje", end='\n') # Imprime un salto de linea al final

It can be modified so that the line ends as one wishes. For example:

print("Mi mensaje", end='') # No imprime nada al final
print("Mi mensaje", end='\t') # Imprime una tabulacion al final

There you can continue traveling a little more.

Greetings!

    
answered by 22.05.2018 в 19:50