Python Boolean | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 ?

18th Oct 2018, 6:18 AM
Siphelele
1 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
18th Oct 2018, 7:03 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar