Why does Python even allow this? Chained comparison jank.

Why does Python even allow this? Chained comparison jank.

Python allows multiple comparisons chained together in the same expression. They have their uses, but the chaining can become confusing when operators of different types are mixed. Why is it that less than and greater than are allowed to be chained together? I think this is confusing and should potentially even be removed from Python.

― mCoding with James Murphy (https://mcoding.io)

Source code: https://github.com/mCodingLLC/VideosSampleCode
Chained comparison docs: https://docs.python.org/3/reference/expressions.html
PEP to expand chained comparison: https://www.python.org/dev/peps/pep-0535/

SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
https://patreon.com/mCoding

Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
https://www.paypal.com/donate/?hosted_button_id=VJY5SLZ8BJHEE

Top patrons and donors: Laura M, Jameson, John Martin, Vahnekie, Pieter G, Sigmanificient

AFFILIATES AND REFERRALS
---------------------------------------------------
Automatically Improve Python Code Quality: https://sourcery.ai/?utm_source=YouTube&utm_campaign=mcoding&utm_medium=aff

BE ACTIVE IN MY COMMUNITY šŸ˜„
---------------------------------------------------
Discord: https://discord.gg/Ye9yJtZQuN
Github: https://github.com/mCodingLLC/
Reddit: https://www.reddit.com/r/mCoding/
Facebook: https://www.facebook.com/james.mcoding

CHAPTERS
---------------------------------------------------
0:00 Intro to chained comparisons
4:25 Good use cases
5:40 Questionable use cases
7:36 Bad use cases
10:42 Numpy use case

python

Post a Comment

0 Comments