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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -