r/pythonhelp • u/[deleted] • Dec 23 '22
if else in one line syntax
My question is how exacly is the syntax on something like:
color = ("white" if val == "1" elif val == "2" "black")
Basically this, but in one line:
if val == "1":
color = "white"
elif val == "2":
color = "black"
Thanks in advance
2
Upvotes
1
u/carcigenicate Dec 24 '22
You'd need two separate conditional expressions; one after the other. There is not
elifwith conditional expressions.