3 ms·
Nice article. I wrote a similar piece some time ago related to booleans, in case anybody is interested: https://blog.rmotr.com/those-tricky-python-booleans-2100
by santiagobasulto 9y ago
Nice article. I wrote a similar piece some time ago related to booleans, in case anybody is interested: https://blog.rmotr.com/those-tricky-python-booleans-2100d5df92c https://blog.rmotr.com/those-tricky-python-booleans-2100d5df...
And to avoid issues with is/==, we recommend our students to always use == (except for `is None`). Also related piece:https://blog.rmotr.com/avoiding-being-bitten-by-python-161b063e7da2 https://blog.rmotr.com/avoiding-being-bitten-by-python-161b0...
- sevensor 9y agoThat's unnecesarily restrictive -- I've gotten great use out of "is". You wouldn't want to use it on an integer, but I've been using namedtuples a lot lately, and "LastKnownConfiguration is CurrentConfiguration" works great to to check whether anything has changed without checking all of the fields for equality.
- santiagobasulto 9y agoYou're very much right and it's a great suggestion. We just suggest that to our students when they're starting in order to help them avoid issues. But there are exceptions.
- sevensor 9y agoFair point -- == versus "is" is a pretty subtle distinction and best avoided by novices.