evaluation of >
sjmachin at lexicon.net
Mon May 8 05:26:34 CEST 2006
On 8/05/2006 12:45 PM, Gary Wessle wrote:
> what does the i > a in this code mean. because the code below is
> giving False for all the iteration. isn't suppose to evaluate each
> value of i to the whole list? thanks
But that's EXACTLY what it's doing; each integer value named i is
notionally being compared to the whole list value named a. However as
the types differ (int vs list), it doesn't even look at the actual
values. Each (rather meaningless) comparison evaluates to False.
Did you read section 5.9 (Comparisons) of the Reference Manual? Deep in
the fine print, it says "objects of different types always compare
unequal, and are ordered consistently but arbitrarily". The answers
might have all been True.
> a = range(8)
> i = 0
> while i < 11:
> print i > a
The print statement is your friend. Use it more effectively.
print i, a, i > a
> i = i + 1
Perhaps if you tell us what you thought the code should do, and/or what
you are investigating, or trying to achieve ....
More information about the Python-list