Chained Comparisons

S

Sathyaish

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
 
F

Fredrik Lundh

Sathyaish said:
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>
 
J

John Machin

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

Sathyaish

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

Dennis Lee Bieber

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

Duncan Booth

Sathyaish said:
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?
 
S

Sathyaish

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/articles/fog0000000022.html
 
P

Peter Otten

Sathyaish said:
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.
False

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

Peter
 
S

Sathyaish

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

Peter Otten

Sathyaish said:
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
 
S

Sathyaish

Thanks, Peter. I do use the interpreter alongside while reading the
documentation and also try out the examples. It was just a matter of
chance that for this particular situation, I did not.

Thank you for the answers, everyone. I hope I am still welcome here for
more questions.
 
S

Steve Holden

Sathyaish said:
Thanks, Peter. I do use the interpreter alongside while reading the
documentation and also try out the examples. It was just a matter of
chance that for this particular situation, I did not.

Thank you for the answers, everyone. I hope I am still welcome here for
more questions.
Absolutely no reason why not. You'll be answering them before long.
Welcome to c.l.py.

regards
Steve
 
F

Fredrik Lundh

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

that Sathyaish's time is more important than your time, of course.

</F>
 
S

Sathyaish

Thanks for the encouragement, Steve. I am learning Python out of
earnest; I am intrigued by several languages such as Ruby, Python and
Lisp.

At work, I program VB6 (used to), VB.NET, C# and C over the Win32
platform.


that Sathyaish's time is more important than your time, of course.

LOL. Certainly didn't mean that. :)
 
G

Grant Edwards

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.

Hell, why not just ask somebody else to do the work for you?
 
D

Dennis Lee Bieber

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.
Yes, this is one of the friendliest groups around -- but we do ask
that people, of any skill level, make the effort to find a solution
first, and if they still can't find an answer, tell us what they've
tried...
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top