range(start,stop)

Moshe Zadka moshez at math.huji.ac.il
Fri Feb 11 16:11:03 EST 2000


On Fri, 11 Feb 2000, Stephane BAUSSON wrote:

> Hello
> 
> Just a question for a Python expert ...
> What the interest for the range function to stop at stop-1 and not at
> stop ?
> For me it does not feel natural to write ....

Well, in the absence of step argument, the invariant:

in range(start, stop) there are stop-start elements 

is very important.

E.g., 

range(0, n) is a list with n elements, so

for i in range(0, n): # equivalent to range(n)
	print "hello"

will print "hello" exactly n times.
--
Moshe Zadka <mzadka at geocities.com>. 
INTERNET: Learn what you know.
Share what you don't.





More information about the Python-list mailing list