4
Continuing my studies in Python, a new doubt arose. Before asking, I researched here on Sopt using the expression "print next to Python" and I did not find anything that could kill my doubt and solve the problem. So come on:
I wrote the following code, very simple, just to illustrate the problem, let’s go to it:
a = int(input("Digite o primeiro número: "))
b = int(input("Digite o segundo número: "))
for i in range(a+1,b):
print(i)
I got the next exit:
Digite o primeiro número: 5
Digite o segundo número: 20
6
7
8
9
10
11
12
13
14
15
16
17
18
19
>>>
The doubt is as follows: Why the function print()
always prints the outputs this way, one underneath the other? How to make it print the outputs next to each other without using list resources?
It worked, but then the exit got all the numbers glued together, like it was a big multi-digit number. However, a change in what you posted made it work. I did so:
print(i,end=",",flush=True)
.– Cadu
That, the end swaps the pattern ' n' which is the line break for "" which is an empty string, so by putting "," it swaps ' n' for comma or any other string you want :)
– Wictor Chaves