Consider this Python code:
assert(a > 0)
assert(b > 0)
assert(a + b > 0)
Can the third assert ever fail? In C/C++, it can if the sum overflows the maximum integer value. How is this handled in Python?
Depends on which version of Python you're using.
Prior to 2.2 or so, you could get an OverflowError
.
Version 2.2-2.7 promote the sum to a long
(arbitrary precision) if it's too large to fit in an int
.
3.0+ has only one integer type, which is arbitrary precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With