+ 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!

6th Feb 2019, 4:20 PM
just trying to think
just trying to think - avatar
2 Respuestas
+ 4
A string evaluates as True if it is not empty. So '' is False, but for example '0' or ' ' is True.
6th Feb 2019, 4:39 PM
HonFu
HonFu - avatar
+ 8
Thanks HonFu ! You really helped me!
6th Feb 2019, 4:42 PM
just trying to think
just trying to think - avatar