On Nov 26, 3:01 pm, Steven D'Aprano <steve +comp.lang.pyt...@pearwood.info> wrote: > On Sat, 26 Nov 2011 22:20:36 +0100, candide wrote: >>SNIP<< > > That is correct. You probably should rarely use `is`. Apart from testing > for None, use of `is` should be rare. > > -- > Steven
With respect, I disagree with advice that the use of a language construct should be rare. All constructs should be used *appropriately*. While in general a particular use of a Python construct may be rare, if the programmer is involved deeply with that rare use, then it is NOT rare to him/her. Thus, for a particular programmer, use of 'is' may be quite frequent because the program they're working on requires knowledge of object identity. The same goes for global variables, by the way. While it's easy to shoot yourself in the foot with global variables, that doesn't lead to never-use-them. It leads to use-them-appropriately-and-carefully. Sorry, you plucked a string of mine. One does not throw a tool out of your tool box because it might be dangerous. Table saws are incredibly dangerous, but in the hands of a skilled operator can be competently and safely used to produce beautiful woodwork. To say *never* use a table saw because it's dangerous is silly. Language constructs are put there intentionally. Advice that they be used *rarely* or *never* should *never* be given ((chuckle)). Just learn what they are, learn how they work, learn what the consequences of misuse can be (loss of a hand, in the case of a table saw), and use them confidently when the circumstances make them the best choice of tool to solve your problem. To make a long comment short (too late!!) learn the differences between 'is' and ==, and use them appropriately. When I was learning Python, I found the two books by Mark Lutz to be filled with information of such things as these. D -- http://mail.python.org/mailman/listinfo/python-list