Chained Comparisons

Discussion in 'Python' started by Sathyaish, Mar 20, 2006.

  1. Sathyaish

    Sathyaish Guest

    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
     
    Sathyaish, Mar 20, 2006
    #1
    1. Advertising

  2. "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>
     
    Fredrik Lundh, Mar 20, 2006
    #2
    1. Advertising

  3. Sathyaish

    John Machin Guest

    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.
     
    John Machin, Mar 20, 2006
    #3
  4. Sathyaish

    Sathyaish Guest

    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.
     
    Sathyaish, Mar 20, 2006
    #4
  5. On 20 Mar 2006 00:16:35 -0800, "Sathyaish" <>
    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.
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Mar 20, 2006
    #5
  6. Sathyaish

    Duncan Booth Guest

    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?
     
    Duncan Booth, Mar 20, 2006
    #6
  7. Sathyaish

    Sathyaish Guest

    >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
     
    Sathyaish, Mar 20, 2006
    #7
  8. Sathyaish

    Peter Otten Guest

    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
     
    Peter Otten, Mar 20, 2006
    #8
  9. Sathyaish

    Sathyaish Guest

    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.
     
    Sathyaish, Mar 20, 2006
    #9
  10. Sathyaish

    Peter Otten Guest

    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
     
    Peter Otten, Mar 20, 2006
    #10
  11. Sathyaish

    Sathyaish Guest

    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.
     
    Sathyaish, Mar 20, 2006
    #11
  12. Sathyaish

    Steve Holden Guest

    Sathyaish wrote:
    > 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
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd www.holdenweb.com
    Love me, love my blog holdenweb.blogspot.com
     
    Steve Holden, Mar 20, 2006
    #12
  13. Duncan Booth wrote:

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


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

    </F>
     
    Fredrik Lundh, Mar 20, 2006
    #13
  14. Sathyaish

    Sathyaish Guest

    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. :)
     
    Sathyaish, Mar 20, 2006
    #14
  15. On 2006-03-20, Sathyaish <> wrote:

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

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

    --
    Grant Edwards grante Yow! I'm encased in the
    at lining of a pure pork
    visi.com sausage!!
     
    Grant Edwards, Mar 20, 2006
    #15
  16. On 20 Mar 2006 02:46:37 -0800, "Sathyaish" <>
    declaimed the following in comp.lang.python:


    > 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...
    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Home Page: <http://www.dm.net/~wulfraed/> <
    > Overflow Page: <http://wlfraed.home.netcom.com/> <
     
    Dennis Lee Bieber, Mar 20, 2006
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike H
    Replies:
    1
    Views:
    742
    Chris Smith
    Feb 27, 2004
  2. Volker Grabsch

    Multiple "cmp"s chained one after another

    Volker Grabsch, May 14, 2005, in forum: Python
    Replies:
    11
    Views:
    520
    Glauco Silva
    May 16, 2005
  3. David S.

    chained attrgetter

    David S., Oct 25, 2006, in forum: Python
    Replies:
    4
    Views:
    333
    David S.
    Oct 26, 2006
  4. Julia
    Replies:
    79
    Views:
    2,612
    James Dow Allen
    Feb 9, 2007
  5. Marcin Ciura
    Replies:
    27
    Views:
    600
    Terry Reedy
    Mar 22, 2007
Loading...

Share This Page