My First Python Script

Ed Hotchkiss edhotchkiss at gmail.com
Fri Sep 16 18:09:42 CEST 2005


Sweet, time to play with python for a whole day today :P

 On 9/16/05, Gary Wilson Jr <gdub at ece.utexas.edu> wrote: 
> 
> Ed Hotchkiss wrote:
> > def ZeroThrough255():
> > x = 0
> > while x <= 255:
> > if len(x) == 1:
> > mySet = '00' + str(x)
> > elif len(x) == 2:
> > mySet = '0' + str(x)
> > else:
> > mySet = x
> > print mySet
> > x +=1
> >
> > ZeroThrough255()
> 
> Instead of using the while loop and a counter, you can use the range()
> function. Using range() and string formatting you could to something like:
> 
> def ZeroThrough255():
> for num in range(256):
> print "%03d" % num
> 
> which, using a list comprehension and the string join() function, could 
> also
> be written as:
> 
> def ZeroThrough255():
> print "\n".join(["%03d" % num for num in range(256)])
> --
> http://mail.python.org/mailman/listinfo/python-list
> 



-- 
edward hotchkiss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050916/438dc0b0/attachment.html>


More information about the Python-list mailing list