Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Chained Comparisons

Reply
Thread Tools

Chained Comparisons

 
 
Sathyaish
Guest
Posts: n/a
 
      03-20-2006
I) What does the following expression evaluate to?

a < b == c

1) (a < b) and (b == c)
2) (a < b) or (b == c)


II) How many operands can be chained for comparison in a single
expression? For e.g, is the under-stated expression a valid comparison
chain?

a < b == c > d

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      03-20-2006
"Sathyaish" wrote:

> I) What does the following expression evaluate to?
>
> a < b == c
>
> 1) (a < b) and (b == c)
> 2) (a < b) or (b == c)


http://docs.python.org/ref/comparisons.html

Formally, if a, b, c, ..., y, z are expressions and opa, opb, ...,
opy are comparison operators, then a opa b opb c ...y opy z
is equivalent to a opa b and b opb c and ... y opy z, except
that each expression is evaluated at most once.

</F>



 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      03-20-2006
On 20/03/2006 5:24 PM, Sathyaish wrote:
> I) What does the following expression evaluate to?
>
> a < b == c
>
> 1) (a < b) and (b == c)
> 2) (a < b) or (b == c)
>


Given the common idiom in mathematics (a <= b <= c) and what it means,
please contemplate which of "and" and "or" might be the more
sensible/useful/plausible answer. Failing that, try to write a small
script which answers your question. If that doesn't work, try reading
section 5.9 (Comparisons) of the Python Reference Manual.

>
> II) How many operands can be chained for comparison in a single
> expression? For e.g, is the under-stated expression a valid comparison
> chain?
>
> a < b == c > d
>


Similar process: infer a plausible answer / script / see the above
manual reference.
 
Reply With Quote
 
Sathyaish
Guest
Posts: n/a
 
      03-20-2006
John,


I did "guess" but I wasn't quite sure and so I asked. OK, I did not
perform a search on the docs, but that was because:

1) It is easier to learn through an interactive medium like a forum;
and
2) A search in the same document you are reading takes you "off" and
"adrift", and as such, is equivalant to a task-switch, because you're
already reading some material from the same help file and are stuck at
some point.

Thanks for the help.

 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      03-20-2006
On 20 Mar 2006 00:16:35 -0800, "Sathyaish" <(E-Mail Removed)>
declaimed the following in comp.lang.python:


> 2) A search in the same document you are reading takes you "off" and
> "adrift", and as such, is equivalant to a task-switch, because you're
> already reading some material from the same help file and are stuck at
> some point.
>

And firing up a news client, posting a message, and /waiting/ for a
response isn't? In most cases, you could have read half the language
reference manual in the time it takes to get an online response.
--
> ================================================== ============ <
> http://www.velocityreviews.com/forums/(E-Mail Removed) | Wulfraed Dennis Lee Bieber KD6MOG <
> (E-Mail Removed) | Bestiaria Support Staff <
> ================================================== ============ <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

 
Reply With Quote
 
Duncan Booth
Guest
Posts: n/a
 
      03-20-2006
Sathyaish wrote:

> I did "guess" but I wasn't quite sure and so I asked. OK, I did not
> perform a search on the docs, but that was because:
>
> 1) It is easier to learn through an interactive medium like a forum;


and what exactly do you think the other people in the forum do? They go off
and read the documentation so that they can be sure to quote it back
accurately to you. So you've saved yourself the bother of looking up the
docs just so that a large number of people can all do it for you.

Please, in future, try looking in the documentation before you post: if
you've looked and can't find what you need, that's fine, or if you've found
it unclear and want more information that is also fine.

> 2) A search in the same document you are reading takes you "off" and
> "adrift", and as such, is equivalant to a task-switch, because you're
> already reading some material from the same help file and are stuck at
> some point.


I've tried reading this several times and can't make sense of what you are
trying to say?
 
Reply With Quote
 
Sathyaish
Guest
Posts: n/a
 
      03-20-2006
>And firing up a news client, posting a message, and /waiting/ for a
response isn't? In most cases, you could have read half the language
reference manual in the time it takes to get an online response.

No, it isn't because you continue reading the same stuff and you have
the stuff open in another window at the same point you left reading it.
That point is not lost. Posting a question in the newsgroup is like
asking someone else; asking some other person to help you out and it
works better than searching the documentation and loosing your train of
thought.

Besides, one doesn't stop reading the help file after posting a
question on the newsgroup until the answer comes. The reading goes on.




>and what exactly do you think the other people in the forum do? They go off

and read the documentation so that they can be sure to quote it back
accurately to you. So you've saved yourself the bother of looking up
the
docs just so that a large number of people can all do it for you.

No, I see the people in this forum engage in trivia instead of
understanding a beginner's anxiety, they engage in these flame wars on
trivial issues.

OK, let me calm down. People here are helpful, too. Python is a new
language for me. I've been programming for over eight years now and
have been there, done that on other forums where I saw a beginner.
Sometimes, a few posts as a beginner can be a bitch.



>I've tried reading this several times and can't make sense of what you are trying to say?


http://www.joelonsoftware.com/articl...000000022.html

 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      03-20-2006
Sathyaish wrote:

> I) What does the following expression evaluate to?
>
> a < b == c
>
> 1) (a < b) and (b == c)
> 2) (a < b) or (b == c)


then later

> 1) It is easier to learn through an interactive medium like a forum;


There is a convenient alternative to asking basic questions on c.l.py or
ploughing through formal docs. When you have a clear conception of the
possible outcomes it is also reliable.

>>> 1 < 2 == 3

False

It can't be 'or' then.
In short, the interactive prompt is *the* tool to learn about language
features and libraries.

Peter
 
Reply With Quote
 
Sathyaish
Guest
Posts: n/a
 
      03-20-2006
OK, I get it. Just stop whining endlessly about it, guys. I *do* use
the interpreter. I posted a question here. Sorry, I committed a sin.

 
Reply With Quote
 
Peter Otten
Guest
Posts: n/a
 
      03-20-2006
Sathyaish wrote:

> OK, I get it. Just stop whining endlessly about it, guys.


Relax. Take what's in it for you and forget about the rest.

> I *do* use the interpreter. I posted a question here.


And I showed you an easy way to answer it yourself. Using the interpreter
doesn't seem to be as ingrained in your working style as I trust it will
become if you stick with Python.

> Sorry, I committed a sin.


Python is a tool, not a religion.

Peter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chained RDP over chained VPN Frank Winkler Cisco 2 06-20-2008 08:02 AM
chained attrgetter David S. Python 4 10-26-2006 01:03 PM
Multiple "cmp"s chained one after another Volker Grabsch Python 11 05-16-2005 01:16 PM
Can abbreviated printStackTrace() output be easily prevented for chained exceptions? Mike H Java 1 02-27-2004 04:09 PM
NAT and chained subnet bomba Cisco 6 10-29-2003 02:09 PM



Advertisments