On Wed, 23 Jan 2008 09:30:28 +0000, Duncan Booth wrote: > Kristian Domke <[EMAIL PROTECTED]> wrote: > >> foo = (not f and 1) or 0 >> >> In this case f may be None or a string. >> >> If I am not wrong here, one could simply write >> >> foo = not f >> >> > Yes, it sounds pretty silly, and not just on the level you spotted. > > The only difference between the two expressions is that the original > sets foo to an integer whereas your version sets it to a bool. So the > question of which is most appropriate actually comes down to what foo is > being used for.
But since Python bools are subclasses from int, both of them are actually ints. One happens to look like 1, and the other looks like True. -- Steven -- http://mail.python.org/mailman/listinfo/python-list