[Tutor] “has a value of True” versus “evaluates true” (was: don't understand iteration)
wesley chun
wescpy at gmail.com
Tue Nov 11 08:35:07 CET 2014
good catch, and definitely a distinction beginners should be more cognizant
of.
it's also good to recognize that a call to "bool(match)" would render that
statement correct, as the built-in/factory function will return what an
object evaluates to (True [re.match object] or/vs.False [None]).
On Mon, Nov 10, 2014 at 5:31 PM, Clayton Kirkwood <crk at godblessthe.us>
wrote:
> I reported it. I feel all grown up now. Kind of like one of the
> boys(girls...)
>
> Clayton:<)
>
>
> >-----Original Message-----
> >From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On
> >Behalf Of Ben Finney
> >Sent: Monday, November 10, 2014 3:24 PM
> >To: tutor at python.org
> >Subject: [Tutor] “has a value of True” versus “evaluates true” (was:
> >don't understand iteration)
> >
> >"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
> >context”.
> >
> >Would you be so kind as to report a bug to that effect
> ><URL:http://bugs.python.org/>?
> >
> >--
> > \ “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
> >
> >_______________________________________________
> >Tutor maillist - Tutor at python.org
> >To unsubscribe or change subscription options:
> >https://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
--
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
+wesley chun <http://google.com/+WesleyChun> : wescpy at gmail : @wescpy
<http://twitter.com/wescpy>
Python training & consulting : http://CyberwebConsulting.com
"Core Python" books : http://CorePython.com
Python blog: http://wescpy.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141110/297bad1d/attachment.html>
More information about the Tutor
mailing list