+ 1
Output
my_list=[False] String="a" if my_list else "b" print(string)
3 Answers
+ 2
A list is True when it contains anything, and False when it contains nothing.
Your list contains something (the object False), so it's not empty.
+ 2
Thanks HonFu [#GoGetThatBugChamp!]
+ 1
What are you trying to achieve?... The code below will return "a", but if you index slice 0, it will return "b". Also Python is case sensitive, so string and String are 2 different variables.
my_list=[False]
if my_list:
string="a"
print(string)
else:
string="b"
print(string)