evaluation of >

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    #1

    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
  • Roy Smith

    #2
    Re: evaluation of &gt;

    In article <87bqu99qv7.fsf @localhost.loca ldomain>,
    Gary Wessle <phddas@yahoo.c om> wrote:
    [color=blue]
    > 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[/color]

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

    Comment

    • John Machin

      #3
      Re: evaluation of &gt;

      On 8/05/2006 12:45 PM, Gary Wessle wrote:
      [color=blue]
      > 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[/color]

      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.[color=blue]
      >
      > a = range(8)
      > i = 0
      > while i < 11:
      > print i > a[/color]

      The print statement is your friend. Use it more effectively.
      print i, a, i > a
      [color=blue]
      > i = i + 1
      >
      > False
      > False[/color]
      [snip]
      Perhaps if you tell us what you thought the code should do, and/or what
      you are investigating, or trying to achieve ....

      Comment

      Working...