On Wed, Mar 30, 2011 at 11:31 AM, Edward Cherlin <echer...@gmail.com> wrote:
> So 'in' is a comparison "operator", is it? I am annoyed at how long it > took me to verify that Python treats it as such, and I am also annoyed > that it is so. > > http://docs.python.org/tutorial/datastructures.html > 5.7. More on Conditions¶ > > The conditions used in while and if statements can contain any > operators, not just comparisons. > As you no doubt know, in triggers the rib __contains__ in the cosmic backbone of Python's special names list, whereas operators like ==, > and < trigger their own specially named reflexes: >>> class Foo: def __contains__(self, value): print ("Yes {} is in the bar".format(value)) return True >>> bar = Foo() >>> "Joe" in bar Yes Joe is in the bar True >>> class Average: def __lt__(self, value): print("Yes {} is better than Average".format(value)) return True >>> bar = Average() >>> "Joe's bar" > bar Yes Joe's bar is better than Average True >>> > The comparison operators in and not in check whether a value occurs > (does not occur) in a sequence. > > I never cared for the misleading a<b<c notation anyway, and won't use it. > > heretic! Kirby
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig