[Tutor] trivial simple program..can it be made more concise?

Steven D'Aprano steve at pearwood.info
Sat Feb 14 13:51:56 CET 2015


On Sat, Feb 14, 2015 at 06:40:56AM -0500, Dave Angel wrote:
> On 02/14/2015 04:07 AM, Steven D'Aprano wrote:
> >On Sat, Feb 14, 2015 at 03:17:28AM +0000, steve10brink at comcast.net wrote:

[...]
> >>for i in range (a):
> >>     print i, '\r',
[...]

> >BUT I'm not sure why you are worried about making it more concise when
> >your code doesn't do what you want, as far as I can tell. You want the
> >counter to be written on the same line, not 640 thousand lines, but when
> >I try it, I get each number written to a different line.
> 
> That's probably because you've dropped the trailing comma that the OP 
> used in the print statements.

So I did :-(

Have I mentioned recently just how awesome Python 3's print is?

for i in range(100000):
    print(i, end='\r')

Much nicer :-)


-- 
Steve


More information about the Tutor mailing list