473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1025
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
7
by: Leo Breebaart | last post by:
Hi all, I have a question about Python and delayed evaluation. Short-circuiting of Boolean expressions implies that in: >>> if a() and b(): any possible side-effects the call to b() might...
8
by: der | last post by:
Hello all, I've a question about order of evaluations in expressions that have && and || operators in them. The question is: will the evalution go left-to-right, no matter what -- even if the...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
77
by: berns | last post by:
Hi All, A coworker and I have been debating the 'correct' expectation of evaluation for the phrase a = b = c. Two different versions of GCC ended up compiling this as b = c; a = b and the other...
9
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
11
by: Pietro Cerutti | last post by:
Hi group, here I come with a question which is quite simple per se, but for which I can't find an answer. Does the C standard guarantee that inside an expression such as (x && y) "y" is...
39
by: Boltar | last post by:
Why does C do lazy evaluation for logical boolean operations but not bitwise ones? Ie: the following program prints "1 2" , not "1 1" under gcc main() { int a = 1; int b = 1; 0 && ++a;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.