Lakshya Tyagi

Posted on

# What will be the output of given python code?

``````a, b = 12, 5
if a+b:
print('True')
else:
print('False')
``````

Write output with explanation in comment

Dave Cridland • Edited

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 performing `x != 0`, so negative numbers also end up as True:

``````> python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
>>> bool(1)
True
>>> bool(0)
False
>>> bool(-1)
True
>>>
``````

Maxim Mosin

'True' because 12+5=17 (int) and bool(int>0) = True

Ugbem Job

Result will be 'True' because by default, all Python Boolean values greater than 0 result to True.

ProMikeCoder2020

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

Nail

True

Sambhav-Jindal-github

True as int value is 17 which is greater than 0, and in python all boolean values greater than 0 given true output.