+ 210

How many people knew this?

I only found this out today. I knew how to use the end elements in the print function e.g: print("Hello","World",end="!") outputs Hello World!,but I never knew the end element stops the interpreter from jumping to the next line. Try this code: print("Hello",end = "") print("World") I thought it would print on two lines instead of 1

18th Jul 2018, 6:13 PM
Shuaib Nuruddin
Shuaib Nuruddin - avatar
107 Answers
+ 99
I think I read it in some course, but forgot about that feature. Thanks :) If you think about it, it makes total sense. end = "something" just replaces the default end = "\n" (aka new line) ending of a print by somehting Same for sep and " " (space)
19th Jul 2018, 10:34 AM
Matthias
Matthias - avatar
19th Jul 2018, 2:55 PM
Shuaib Nuruddin
Shuaib Nuruddin - avatar
+ 23
cool..😁😃but I knew that😃👍
20th Jul 2018, 5:08 PM
💞ⓢⓦⓐⓣⓘ💞
💞ⓢⓦⓐⓣⓘ💞 - avatar
+ 20
i didn't knew that😅 Thanks for info
24th Jul 2018, 12:06 PM
Jaydeep Khatri
Jaydeep Khatri - avatar
+ 17
Shuja Abrar No, end="" does not leave a space. The next print will be concatenated, with no space. end=" " will leave a space
19th Jul 2018, 3:58 PM
Matthias
Matthias - avatar
+ 16
try print("hello", "world", sep = "_")
19th Jul 2018, 8:20 AM
Mert Yazıcı
Mert Yazıcı - avatar
+ 14
Knew it😄 But it will be helpful for others.👍👍
23rd Jul 2018, 4:41 PM
Mitali
Mitali - avatar
+ 12
thanks for info📕 What does the JUMP_LINK__&&__Python__&&__JUMP_LINK say? This is helpfull !!!👍👍👍
21st Jul 2018, 1:22 PM
Biel Blue
Biel Blue - avatar
+ 11
Great 😊i didn't knew that 😃
5th Nov 2018, 2:05 AM
Vishnu
Vishnu - avatar
+ 10
Great . I didn't know that . Thanx
19th Jul 2018, 6:51 AM
Mahmud amen
Mahmud amen - avatar
+ 9
One rejection isn't the end of the world, if you put your mind to it, you can acomplish anything :). Make it you can do it
23rd Jul 2018, 7:46 PM
José Baltazar Castillo Rodríguez
José Baltazar Castillo Rodríguez - avatar
+ 9
end defines how print ends and newline ("\n") is default, sep defines how different arguments in print are separated and whitespace is default (" ") Type help(print) and run in compiler to see more! But strange SoloLearn Python 3 Tutorial never mentioned.
23rd Jul 2018, 8:26 PM
Seb TheS
Seb TheS - avatar
+ 8
Thanks Matthias. Never thought of it in that way.
19th Jul 2018, 2:57 PM
Shuaib Nuruddin
Shuaib Nuruddin - avatar
+ 8
Thanks for the information about print("hello",end="") to supress the \n at end of the print. I always used sys.stdout.write(...) or sys.stdout.write(format % vals ) where format is the C format string and vals is a tuple of things to print. Note: you have to import sys to use sys.stdout.write . """ C's printf function """ def printf( format, *vals ): sys.stdout.write( format % vals ) By the way, does print("foo", end="") only work in python 3? in python 2.3 the code above get a syntax error. On my old laptop, I still have to use sys.stdout.write("foo") to supress the ending "\n" .
20th Jul 2018, 6:09 AM
Rick Shiffman
Rick Shiffman - avatar
+ 8
always had this thing in my mind but never bothered to find it out thanlks forr sharingg 🤗
23rd Jul 2018, 4:36 PM
Amit Singh
Amit Singh - avatar
+ 8
Yes! i found out when i was researching for my histogram contest. i used it to draw histogram in this code 😁👇👇 https://code.sololearn.com/cvODAhcEuh2t/?ref=app
23rd Jul 2018, 9:09 PM
Evans Teye
Evans Teye - avatar
+ 7
What does the Python say? yes all are set by default values as per the function definition.
22nd Jul 2018, 3:07 PM
Gaurav Singh
Gaurav Singh - avatar
+ 7
I knew it :) end="" is useful when you don't want to go to new line. It is often needed to print more things on one line.
23rd Jul 2018, 4:25 PM
michal
+ 7
The nice thing is that you can put any character or piece of code after end= and it will effect the end of the print statement (this can work for sep= , too). So, if you still want a newline at the end of your statement, you can write like this: print("Hello", end="\n") print("World") ''' outputs: Hello World '''
23rd Jul 2018, 6:44 PM
Ricardo
+ 6
cool
18th Jul 2018, 6:14 PM
Satyam