When is 0 not 0? When SymPy made it into an instance of its special Zero class of course! 😅
*AND* you can't convert that to a Decimal by just casting it either 😬
When is 0 not 0? When SymPy made it into an instance of its special Zero class of course! 😅
*AND* you can't convert that to a Decimal by just casting it either 😬
@wizzwizz4 Testing zero with `is` is safe because it's got a fixed memory address: https://realpython.com/python-is-identity-vs-equality/#when-only-some-integers-are-interned
Try your code with 256 and 257 - you'll see that 256 gives True and 257 gives False.
> You should not be writing code that relies on this behaviour in the first place.
I'm not.
That was just a screenshot of ipdb where I was debugging and surprised that an instance printed as "0" but wasn't the int 0.
Happy to add a screenshot with a better way of demonstrating that the value I had in the dictionary was `sp.S.Zero` and not `int(0)`, even though they `== 0` as `True` - what _should_ I have done?
Python developer working with data and royalties at Mixcloud.Lover of testing and linting. User of Linux. Author of https://github.com/jamescooke/flake8-aaa
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.