470,810 Members | 866 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

evaluation of >

Hi

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

a = range(8)
i = 0
while i < 11:
print i > a
i = i + 1

False
False
False
False
False
False
False
False
False
False
False
thanks
May 8 '06 #1
2 982
In article <87************@localhost.localdomain>,
Gary Wessle <ph****@yahoo.com> wrote:
Hi

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

a = range(8)
i = 0
while i < 11:
print i > a
i = i + 1

False
False
False
False
False
False
False
False
False
False
False
thanks


I'm not sure what you're expecting to happen, or what you're trying to do,
but comparing an integer to a list is (almost) meaningless.

See http://docs.python.org/ref/comparisons.html, where it says, "objects of
different types always compare unequal, and are ordered consistently but
arbitrarily".
May 8 '06 #2
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

False
False

[snip]
Perhaps if you tell us what you thought the code should do, and/or what
you are investigating, or trying to achieve ....
May 8 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Bhushit Joshipura | last post: by
7 posts views Thread by Leo Breebaart | last post: by
8 posts views Thread by der | last post: by
21 posts views Thread by dragoncoder | last post: by
77 posts views Thread by berns | last post: by
9 posts views Thread by sturlamolden | last post: by
54 posts views Thread by Rasjid | last post: by
11 posts views Thread by Pietro Cerutti | last post: by
39 posts views Thread by Boltar | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.