+ 7
Explain the output
Hello dear SoloLearners! I have been playing challenges and I found this quiz print(['abc', 'def'][bool('spam')]) The output is def I understand that True = 1, so list[1] = def But why bool('spam') = True? I don't understand. Please explain!
2 Respuestas
+ 4
A string evaluates as True if it is not empty.
So '' is False, but for example '0' or ' ' is True.
+ 8
Thanks HonFu ! You really helped me!