Re: Simple Python question for some

Discussion in 'Python' started by Mark Lawrence, Oct 29, 2012.

  1. On 28/10/2012 23:51, Mark L. Hotz wrote:
    > I have what I think should be a relatively simple question for someone who
    > is knowledgeable about Python.


    Sorry you've come to the wrong place :)

    >
    > At the IDLE prompt, when I enter "b" > 99, it responds True. In fact, it
    > doesn't matter which number is entered here, "b" is always greater (e.g. "b"
    >> 1 == True; "b" > 100000 == True, or "b" < 99 = False).

    >
    > Why is this true? If I use ord("b") it returns 98, so Python cannot be
    > using the ASCII or Unicode value when interpreting "b" > 99. When I sort a
    > mixed list using Python, and the list contains "b" among a series of numeric
    > values, "b" is always sorted as last, indicating that it has a value greater
    > than the highest number?
    >
    > How do I prove that "b" is greater than any number? Or is it something very
    > simple, and Python simply orders characters after numbers, or perhaps Python
    > only interprets numbers like 99 as a 9 (i.e. ord("9") == 57)?
    >
    > Thank you.
    >


    The behaviour of Python between version 2 and 3 has been changed hence.

    Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit
    (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 'b' > 99

    True

    Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32
    bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 'b' > 99

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: unorderable types: str() > int()

    --
    Cheers.

    Mark Lawrence.
    Mark Lawrence, Oct 29, 2012
    #1
    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. Eric
    Replies:
    2
    Views:
    1,459
    Tommy
    Feb 13, 2004
  2. Chris Rebert

    Re: Simple Python question for some

    Chris Rebert, Oct 29, 2012, in forum: Python
    Replies:
    0
    Views:
    161
    Chris Rebert
    Oct 29, 2012
  3. Chris Angelico

    Re: Simple Python question for some

    Chris Angelico, Oct 29, 2012, in forum: Python
    Replies:
    0
    Views:
    167
    Chris Angelico
    Oct 29, 2012
  4. Evan Driscoll

    Re: Re: Simple Python question for some

    Evan Driscoll, Oct 29, 2012, in forum: Python
    Replies:
    0
    Views:
    143
    Evan Driscoll
    Oct 29, 2012
  5. Chris Angelico

    Re: Re: Simple Python question for some

    Chris Angelico, Oct 29, 2012, in forum: Python
    Replies:
    0
    Views:
    156
    Chris Angelico
    Oct 29, 2012
Loading...

Share This Page