Back to Browse

Why I don't like Python's chained comparisons

59.0K views
Sep 4, 2021
11:27

Are multiple comparisons unintuitive or am I out of touch? 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 ⭐ --------------------------------------------------- Patreon: https://patreon.com/mCoding Paypal: https://www.paypal.com/donate/?hosted_button_id=VJY5SLZ8BJHEE Other donations: https://mcoding.io/donate Top patrons and donors: Laura M, Jameson, John Martin, Vahnekie, Pieter G, Sigmanificient 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

Download

1 formats

Video Formats

360pmp416.8 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Why I don't like Python's chained comparisons | NatokHD