Python Boolean | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren

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
1 Antwort
+ 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