0

I want to know, when I can use this expression: end="".

print('*',end="")
martineau
  • 112,593
  • 23
  • 157
  • 280
  • 1
    It means don't add a line break – AK47 Aug 24 '20 at 23:19
  • That is merely a keyword argument to the function `print`. You can use it in *any* function call, although, it probably won't be a valid argument – juanpa.arrivillaga Aug 24 '20 at 23:20
  • 2
    Does this answer your question? [Python : meaning of end='' in the statement print("\t",end='')](https://stackoverflow.com/questions/27312273/python-meaning-of-end-in-the-statement-print-t-end) – MendelG Aug 24 '20 at 23:21
  • Does this answer your question? [python print end=' '](https://stackoverflow.com/questions/2456148/python-print-end) – MrJuicyBacon Aug 24 '20 at 23:23
  • See the documentation: [**`print`**](https://docs.python.org/3/library/functions.html#print) – Peter Wood Aug 24 '20 at 23:30
  • And here's the [documentation](https://docs.python.org/3/library/functions.html#print). – martineau Aug 25 '20 at 00:26

2 Answers2

4

Normally python appends a newline to each print statement, you can replace the newline with something of your choosing with the end paramter.

>>> print('hi')
hi
>>> print('hi', end='')
hi>>> print('hi', end='bye')
hibye>>>
Jon
  • 328
  • 3
  • 8
0

One of the default parameter to the print function is end = '\n'. So what that means is by default python inserts a newline right after your print statement. Most of the time this is handy and reduces having to use the newline every time. But sometimes this is not the case and we don't want it to insert a newline character in the end. So to override this default parameter we give an end argument to the print statement, and the statement will end with whatever you have provided. So in this case, we have over rode it to '', or nothing in the end, which cancels out the default newline character.

Dharman
  • 26,923
  • 21
  • 73
  • 125