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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 anint.3.0+ has only one integer type, which is arbitrary precision.