0
Explain plz.
What is this bool and why this prints true? https://code.sololearn.com/c7lh9E7Z7vr3/?ref=app
3 Respostas
+ 4
the reason why
print (bool("ab"))
results to True is:
▪︎a str is an iterable object (like list, set, dict). all iterable objects are considered to be True, if they are non-empty.
when using:
print (bool(""))
the result will be False
having that in consideration, we can use this to check if iterables are empty or not:
res = []
if res:
...
+ 2
its a bool cause you used bool() and it's true because it has something.
look
https://code.sololearn.com/cA0rRWSSyfIT/?ref=app
0
I think it's because there is a value different from zero inside bool.