ARTICLE AD BOX
Check the reference page of print. By default there is a newline character appended to the item being printed (end='\n'), and end='' is used to make it printed on the same line.
And print() prints an empty newline, which is necessary to keep on printing on the next line.
EDITED: added an example.
Actually you could also use this:
2 Comments
@Robᵩ Of course there're many ways to write the code short, however this is not something like IOCCC and the purpose of source code is for people to read. I don't see any benefit to write like that. Also, are you sure you're providing a correct example? You may try n=1.
2013-12-04T14:30:41.887Z+00:00
In Python 3.x, the end=' ' is used to place a space after the displayed string instead of a newline.
please refer this for a further explanation.
So I'm new to this whole coding thing, but I came up with this code. It's probably not as sophisticated as the other stuff, but it does the job.
spam = ['apples', 'bananas', 'tofu', 'cats'] def fruits(): i = 0 while i != len(spam): if len(spam) != i : print ('and', spam[i]) i += 1 fruits()try this!
use this to understand
for i in range(0,52): print(5*"fiof" ,end=" ")just put different things here in end and also use with sep
29.7k11 gold badges97 silver badges104 bronze badges
3 Comments
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?
2024-03-07T00:16:19.017Z+00:00
Explore related questions
See similar questions with these tags.
