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'm bited once: >>> '' in {} == False False >>> ('' in {}) == False True
# '' in {} == False ==>> ('' in {}) and ({} == False) ==>> False!
I think only compare operations should be chained.
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):
a = "a" b = "abc" c = "abcde" a in b in c True
On Tue, Feb 28, 2017 at 6:56 PM, 语言破碎处 <mlet_it_bew@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@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.

On 01/03/17 02:56, 语言破碎处 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.
I think comparing against False (or True) is bad idea. I would certainly reject any code doing it that came past me for review. Use "not" instead. -- Rhodri James *-* Kynesim Ltd
participants (4)
-
Chris Angelico
-
David Mertz
-
Rhodri James
-
语言破碎处