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 ?
1 Réponse
+ 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