108 AnswersNew Answer
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
7/18/2018 6:13:38 PMWhat does the Python say?
108 AnswersNew Answer
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)
for i in range(5): print(i,end="") prints 01234 whereas, for i in range(5): print(i) prints 0 1 2 3 4
try this code https://code.sololearn.com/cQjfP8HJ0B4K/?ref=app
cool..😁😃but I knew that😃👍
i didn't knew that😅 Thanks for info
Shuja Abrar No, end="" does not leave a space. The next print will be concatenated, with no space. end=" " will leave a space
try print("hello", "world", sep = "_")
Knew it😄 But it will be helpful for others.👍👍
thanks for info📕 What does the Python say? This is helpfull !!!👍👍👍
Great 😊i didn't knew that 😃
Great . I didn't know that . Thanx
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
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.
Thanks Matthias. Never thought of it in that way.
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" .
always had this thing in my mind but never bothered to find it out thanlks forr sharingg 🤗
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
What does the Python say? yes all are set by default values as per the function definition.
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.
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 '''
Learn Playing. Play Learning
SoloLearn Inc.4 Embarcadero Center, Suite 1455
Send us a message