a, b = 12, 5
if a+b:
print('True')
else:
print('False')
Write output with explanation in comment
a, b = 12, 5
if a+b:
print('True')
else:
print('False')
Write output with explanation in comment
For further actions, you may consider blocking this person and/or reporting abuse
KAMAL KISHOR -
Mike Young -
Mike Young -
Romina Mendez -
Top comments (7)
All these answers are saying
True
, and that's right, but many of them suggest if an integer is greater than zero it's True, and that's not quite right - in effect, a coercion of an integer to boolean is performingx != 0
, so negative numbers also end up as True:'True' because 12+5=17 (int) and bool(int>0) = True
Result will be 'True' because by default, all Python Boolean values greater than 0 result to True.
Via the decoupling a becames 12 and b becames 5 thus their joined sum becames 17. Since 17 is a truthy value it passed the if check and thus prints True
True
True
True as int value is 17 which is greater than 0, and in python all boolean values greater than 0 given true output.