[Tutor] String comparison

Rob rob@uselesspython.com
Thu, 8 Aug 2002 09:18:02 -0500


> >     How do I perform a string comparison in Python.
>
> if str1 == str2:...
> if str1 < str2:....
>
> etc
>
> Also using cmp()
>
> cmp(str1,str2)
>
> returns -1,0,1 for less than, equal, greater than...
>
>

I wrote a short article called "Joe Useless Writes A Program" for Useless
Python earlier this summer, in which cmp() is explained (a little bit,
anyway) and fleshed into a whole program. If anyone's interested, here's the
URL:

http://uselesspython.com/JoeUselessWritesAProgram.html

It still needs a bit of work, but I don't think it's too shabby.

Rob