Explain plz. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Explain plz.

What is this bool and why this prints true? https://code.sololearn.com/c7lh9E7Z7vr3/?ref=app

4th Jun 2021, 9:41 AM
Aayush Jat
Aayush Jat - avatar
3 Antworten
+ 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: ...
4th Jun 2021, 11:22 AM
Lothar
Lothar - avatar
+ 2
its a bool cause you used bool() and it's true because it has something. look https://code.sololearn.com/cA0rRWSSyfIT/?ref=app
4th Jun 2021, 10:07 AM
Slick
Slick - avatar
0
I think it's because there is a value different from zero inside bool.
4th Jun 2021, 9:47 AM
Mihail
Mihail - avatar