Am I right in thinking there is no way to put an if statement and an else statement on line in Python?
Posted
by
Louise
on Stack Overflow
See other posts from Stack Overflow
or by Louise
Published on 2014-06-12T21:19:03Z
Indexed on
2014/06/12
21:24 UTC
Read the original article
Hit count: 286
python
|if-statement
Am I right in thinking I can't put an if-statement and the corresponding else-statement on one line in Python?
NB:
variable = value1 if condition else value2
is NOT two statements. It's one statement which can take the value of one of two expressions.
I want to do something like
if condition a=value else b=value
Am I right in thinking this requires a full if-else in Python? Like
if condition:
a=value
else:
b=value
Thanks,
Louise
© Stack Overflow or respective owner