true = 1
Steven Majewski
sdm7g at Virginia.EDU
Sat Jan 12 15:00:35 EST 2002
Note that you can also use:
if 'true' : ...
as well as:
false = not 'true'
But if somthing was going to be bound to the variables 'True' and 'False',
then a Boolean class like Jeremy Cromwell's suggestion makes more sense
than 1 or 0, because I suspect that some folk might fall into:
if test() == False
and his boolean class does the right coercion.
The other advantage of a class over constant 0 or 1 is that it can
have a better printable representation for __repr__ and __str__.
Another option:
you can define functions that can be either boolean tests (when
given an argument) or return Boolean values (with no arg):
>>> def True(*arg):
... if arg: return arg[0]
... else: return not arg
...
>>> def False(*arg):
... if arg: return not arg[0]
... else: return arg
...
>>> x = False()
>>> if False(x):
... print 'false'
...
false
-- Steve Majewski
More information about the Python-list
mailing list