Nested for loop problem
Duncan Smith
buzzard at urubu.freeserve.co.uk
Sat Nov 8 22:38:21 EST 2003
"Don Low" <m_tessier at sympatico.ca> wrote in message
news:boju9f$1fgli4$1 at ID-145503.news.uni-berlin.de...
> In article <3fad715f$0$58715$e4fe514c at news.xs4all.nl>, Irmen de Jong
wrote:
> > Don Low wrote:
> >>>>>for x in range(2, 2):
> >>
> >> ... print x
> >> ...
> >>
> >> Since x prints nothing, I guess x = NULL. If I try:
> >
> > That's your misunderstanding. That loop does *nothing*,
> > it doesn't enter the loop body. When you're looping over
> > an empty sequence, the loop body is never entered.
>
> OK, so python knows not to even bother going through the loop if the
> range is [].
> >
> > (also, NULL is meaningless in Python. I think you meant
> > None, right?)
>
> Yes, as in range(2, 2) yields nothing.
>
It doesn't return nothing; it returns an empty list. You *can* write a
function that returns None.
>>> def func():
return
>>> a = func()
>>> a is None
True
>>>
Duncan
More information about the Python-list
mailing list