[Tutor] Printing with no newline :(

Alan Gauld alan.gauld at btinternet.com
Sun Nov 6 16:39:03 CET 2011


On 06/11/11 10:23, Sarma Tangirala wrote:

> I'm sorry. Didn't notice the python 3 part, I just joined the list and
> did not look at the OPs post. Sorry about that.

welcome to the list :-)

> Please bear with me on this, but does the following not print "end" for
> every iteration of "items"?
>
> for item in items:
>       print(item, end="")

No, end is a new optional parameter for the print function in Python 3.
Recall that in Python2 print was a command whereas in Python 3 it is a 
function which has a couple of new options:

---------------
Help on built-in function print in module builtins:

print(...)
     print(value, ..., sep=' ', end='\n', file=sys.stdout)

     Prints the values to a stream, or to sys.stdout by default.
     Optional keyword arguments:
     file: a file-like object (stream); defaults to the current sys.stdout.
     sep:  string inserted between values, default a space.
     end:  string appended after the last value, default a newline.



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list