[Tutor] “has a value of True” versus “evaluates true” (was: don't understand iteration)

Ben Finney ben+python at benfinney.id.au
Tue Nov 11 00:24:00 CET 2014

"Clayton Kirkwood" <crk at godblessthe.us> writes:

> Also of confusion, the library reference says:
> Match objects always have a boolean value of True. Since match() and
> search() return None when there is no match, you can test whether there was
> a match with a simple if statement:
> match = re.search(pattern, string)
> if match:
>     process(match)

The documentation is incorrect, as you point out: “have a boolean value
of True” implies that the value is identical to the built-in ‘True’
constant, which is never the case for these objects.

Instead, the passage above should say “evaluates true in a boolean

Would you be so kind as to report a bug to that effect

 \       “The Vatican is not a state.… a state must have people. There |
  `\    are no Vaticanians.… No-one gets born in the Vatican except by |
_o__)        an unfortunate accident.” —Geoffrey Robertson, 2010-09-18 |
Ben Finney

More information about the Tutor mailing list