comparing digits and letters 1 >’a’ outputs an error

Python Land Forums The Python Tutorial comparing digits and letters 1 >’a’ outputs an error

Viewing 2 reply threads
  • Author
    Posts
    • #1608
      Lu
      Participant

      Hi! Thanks for this tutorial, in section Booleans and Conditionals I get the following error when comparing a digit and a letter:

      `>>> 1 < ‘a’
      Traceback (most recent call last):
      File “<stdin>”, line 1, in <module>
      TypeError: ‘<‘ not supported between instances of ‘int’ and ‘str’

    • #1631
      Erik van Baaren
      Keymaster

      Hi Lu,

      Python tells you:
      ‘<‘ not supported between instances of ‘int’ and ‘str’

      This means you can’t compare two different types in Python. You can compare numbers with numbers, and you can also compare letters with letters.

      I can see why you tried though since I gave an example where I did exactly that. I updated the tutorial page because I meant to give the example ‘1’ < 'a' instead of 1 < 'a'.

    • #1663
      Lu
      Participant

      Thanks,

      If I follow this correctly then in the case ‘1’<‘a’ the 1 is not an integer type but the unicode character ‘1’

      When looking at the character map, ‘!’ would be the smallest of all unicode characters and ‘ﻼ’ will be the largest. Python evaluated it to True

      >>> '!'<'ﻼ'
      True
Viewing 2 reply threads
  • You must be logged in to reply to this topic.