Python Boolean | Sololearn: Learn to code for FREE!

0

Python Boolean

i'm struggling with the code to convert the number 1 to a boolean ........can anyone show me how this is done ..........and why do we need to convert int into booleans ?

10/18/2018 6:18:12 AM

Siphelele

1 Answer

New Answer

+6

x = bool(1) print(x) >>> True We often "convert" other data types to boolean to explicitly use them as predicates. However, they of course carry their "boolean potential" which is used when using boolean operators on them, without the necessity to change the type. while 8: print('Infinite loop') will produce an endless loop, because 8 (as any other number apart from 0) is True