[Tutor] tutorial 5.1.3
David Scott
dedoleo@hotmail.com
Thu May 22 14:51:20 2003
In the Python Tutorial (the one that comes with Python), in section 5.1.3,
there is something that I do not understand:
>>>def f(x): return x % 2 != 0 and x % 3 != 0
...
>>>filter(f, range(2, 25))
[5, 7, 11, 13, 17, 19, 23]
That example is used to compute primes.
>From what I understand, the "return" statement is returning the tested value
(passed in from the range) if it passes both tests. However, it seems to me
that the return statement would return either a 1 or a 0 and nothing else,
because of the "and".
return (test expression) and (test expression). If both are true, then the
"and" is true. else, the entire statement is false.
What am I missing or misunderstanding here?
--------------------------------------
dedoleo@hotmail.com
http://groups.msn.com/WalledCity
_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=features/junkmail