Lets say we have the following:
my_condition = True
print('AAA' if my_condition else 'BBB')
The output would be:
AAA
Conversely, if my_condition
became False
:
my_condition = False
print('AAA' if my_condition else 'BBB')
The output would be:
BBB
Now, lets say I wanted to put that same if my_condition else 'BBB'
at the end of a bunch of different print functions.
Is there a way to alias that statement?
So instead of:
my_condition = True
print('AAA' if my_condition else 'BBB')
I wanted something like this:
myStatement = if my_condition else 'BBB'
my_condition = True
print('AAA' myStatement)
Except, as I've already discovered, this doesn't work. Is it possible to alias this If-Else statement?
Edit I should have mentioned that I'm running this on Python 2.7, however I do appreciate the 3.X solutions.