0
Python: why are strings evaluated true?
print("aaa" if True else "zzz") Why is the output aaa?
5 odpowiedzi
+ 2
Not all strings are True - an empty string '' is False.
This allows for convenient stuff like:
name = input() or 'anonymous'
0
Jayakrishna🇮🇳
What is the condition here?
0
Solus The boolean.
0
Ternary operator:
a if condition else b
It means if the condition is true then a, else b.
"aaa" if True else "zzz"
The condition is True. Goes print("aaa")