3 ms·
can't use print x anymore, which also gets rid of "print x,", which printed something without making a newline, for one thing.
by jimmaswell 13y ago
can't use print x anymore, which also gets rid of "print x,", which printed something without making a newline, for one thing.
- SoftwareMaven 13y agoprint(x, end='') Not quite as nice, but not exactly unusable. https://docs.python.org/3.1/library/functions.html#print https://docs.python.org/3.1/library/functions.html#print
- jimmaswell 13y agoIt's a lot less "pythonic".
- tim333 13y agoDunno. The 3 way is more "Explicit is better than implicit." Though it's a shame Python 3 messes up http://xkcd.com/353/ http://xkcd.com/353/
- tim333 13y agoDunno. The 3 way is more "Explicit is better than implicit." Though it's a shame Python 3 messes up http://xkcd.com/353/ http://xkcd.com/353/
- dragonwriter 13y ago> can't use print x anymore Yes, its a function not a statement, so its now print(x). > which also gets rid of "print x,", which printed something without making a newline, for one thing. Sure, you have to do: print(x,end=' ') if you want to space separate things printed on separate code lines on the same output line. Of course, if the extra keystrokes bother you, its really not much one-time cost to toss together a library that provides a function that gets rid of them, while keeping the rest of the power of the print function: def p(*args, **kwargs): kwargs = {'end': ' '}.update(kwargs) print(*args,**kwargs) Though if I was going to bother to do that, I'd probably do it with the same separator for multiple items on the same line as for items on different lines: def p(*args, **kwargs): kwargs = {'sep': ' ', 'end': ' '}.update(kwargs) print(*args,**kwargs) or, further leveraging print-is-a-function: import functools p = functools.partial(print, sep=' ',end=' ')