Am I right in thinking there is no way to put an if statement and an else statement on line in Python?
- by Louise
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