0
Hello,
I already know that adding n to a string will cause a new line to start, but when I want to skip a line I should use n at the end/beginning of a string or should put a print() alone?
For example:
palavra = input("digite uma palavra: ")
for letra in palavra:
print(letra, end=" ")
print("Isso é um teste")
in that case let’s say I want to separate palavra
of "isso é um teste"
by two lines.
I should do print("\n\nIsso é um teste")
or put two prints before print("isso é um teste")
?
This is a very strange question, because in practice it makes no difference. I believe that
\n
is a better option because it is leaner and without impairing the readability of the code– Rafael Tavares
Which is more compact I know, but what if I need to skip 3 lines? then I would have to do n n n. I don’t know about you, but this way it looks weird.
– vagnerPG
Just do
print('\n' * 3)
- will print 3\n
(plus the\n
that the veryprint
already includes at the end)– hkotsubo
Mmm, good idea. I would never have thought of that kkkk
– vagnerPG
It depends on the situation. There will be situations that will be necessary to use a
"\n"
. In other situations the"\n * m"
(m = integer) and in other situations it will be necessary"print()"
.– Solkarped