python - Assign two variables with ternary operator -


is there way variable assignments(as shown below) using ternary operators in python:

if(x>1):     y="yes" else:     z="yes" 

something (x='yes') if(x>1) else (z='yes'), gives error. there other way this?

i know single variable assignments can done this: x="yes" if(l==0) else "no"

edit: assume x, y & z assigned value before run.

you can use exec function this:

exec("y='yes'" if x > 1  else "z='yes'") 

Comments