Velocity Reviews > Chained Comparisons

# 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

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>

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
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.

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
already reading some material from the same help file and are stuck at
some point.

Thanks for the help.

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 <
> ================================================== ============ <
> Overflow Page: <http://wlfraed.home.netcom.com/> <

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

> 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?

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
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

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

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.

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