[Chicago] Why is '' > 0 True?

Robare, Phillip (TEKSystems) proba at allstate.com
Tue Dec 8 14:40:58 EST 2015

A bug in our code has been hunted down and at its core is the fact that in Python

'' > 0

is True.  It is actually true for any string and any integer.

My expectation would be that the string form of '>' would coerce its right argument to something comparable to its left argument.  But

'' > str(0)

is False.

Obviously we should not be trying to order mixtures of strings and integers so the bug is fixed, but I am wondering why this works the way it does.  Can anyone enlighten me?

Phil Robare

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20151208/9894cbe5/attachment.html>

More information about the Chicago mailing list