Output | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Output

my_list=[False] String="a" if my_list else "b" print(string)

23rd Jul 2019, 4:21 PM
Raju Singh
Raju Singh - avatar
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.
23rd Jul 2019, 4:52 PM
HonFu
HonFu - avatar
23rd Jul 2019, 4:56 PM
Raju Singh
Raju Singh - avatar
+ 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)
23rd Jul 2019, 4:33 PM
Steven M
Steven M - avatar