General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Lawrence D’Oliveiro
Lex Fridman
comments
Comments by "Lawrence D’Oliveiro" (@lawrencedoliveiro9104) on "Best hidden feature of Python | Chaining comparison operators" video.
Or how about this: >>> a = 9999 >>> b = 3 >>> a + b is b + a False
2
Is there such a thing as overuse? For example, instead of if download_limit != None and bytes_downloaded >= download_limit : break I could write if None != download_limit <= bytes_downloaded : break But should I?
1
Ummm ... who said anything about “==”?
1
Who said I was “confusing” anything with anything?
1
This feature is implemented entirely at the syntactic level by the compiler. This means it works even for your own custom types where you write your own definitions for e.g. __lt__, __eq__ and the other comparison methods: you just write them as regular two-argument functions, and Python takes care of the rest.
1
Another handy feature of Python’s operators is actually very subtle. So subtle, that I only discovered it by accident one day: the operator precedence differs slightly from C. Which lets you write things like flags & mask != 0 or flags & mask1 == mask2 Any C programmers squirming at that? Because the operator precedence in C requires you to write (flags & mask) != 0 (flags & mask1) == mask2 otherwise they won’t do what you expect! Now, changing the precedence rules in C to remove the need for these parentheses would, in principle, be backward-incompatible; but can anyone come up with actual real-world C code that would break if the rules were changed to be more like Python?
1