a bad feature in Python syntax

I'm bited once: >>> '' in {} == False False >>> ('' in {}) == False True # '' in {} == False ==>> ('' in {}) and ({} == False) ==>> False! I think only compare operations should be chained.

On Wed, Mar 1, 2017 at 1:56 PM, 语言破碎处 <mlet_it_bew@126.com> wrote:
I do feel your pain, but generally, you shouldn't be using "== False" to negate a condition. That's what the "not" operator is for - or inverted conditions.
'' not in {} True
Much better. :) ChrisA

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):
On Tue, Feb 28, 2017 at 6:56 PM, 语言破碎处 <mlet_it_bew@126.com> wrote:
-- 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.

On Wed, Mar 1, 2017 at 1:56 PM, 语言破碎处 <mlet_it_bew@126.com> wrote:
I do feel your pain, but generally, you shouldn't be using "== False" to negate a condition. That's what the "not" operator is for - or inverted conditions.
'' not in {} True
Much better. :) ChrisA

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):
On Tue, Feb 28, 2017 at 6:56 PM, 语言破碎处 <mlet_it_bew@126.com> wrote:
-- 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.
participants (4)
-
Chris Angelico
-
David Mertz
-
Rhodri James
-
语言破碎处