[Python-ideas] a bad feature in Python syntax
David Mertz
mertz at gnosis.cx
Tue Feb 28 23:50:21 EST 2017
OK, I'm impressed!
I've written about and taught Python for almost 20 years. I never realized
`in` was a chained comparison. I'm pretty sure I've never seen it used
that way "in the wild." I also never tried using `is` in a chained way
until just now.
That said, there are at least three things perverse about the examples
below, and they should *definitely* never be used in real code.
This is vaguely plausible (for variable defined in some more interesting
way where the substring relation is not so obvious; say content read from
files):
>>> a = "a"
>>> b = "abc"
>>> c = "abcde"
>>> a in b in c
True
On Tue, Feb 28, 2017 at 6:56 PM, 语言破碎处 <mlet_it_bew at 126.com> wrote:
> I'm bited once:
> >>> '' in {} == False
> False
> >>> ('' in {}) == False
> True
>
> # '' in {} == False ==>> ('' in {}) and ({} == False) ==>> False!
>
> I think only compare operations should be chained.
>
>
>
>
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170228/a9de82d5/attachment.html>
More information about the Python-ideas
mailing list