Here is the example:
age = 10
reject = False
if age < 10:
st = 'Kid'
reject = True
else:
st='Adult'
reject = False
Is it possible? Something like:
statement1:statement2 if age < 10 else statement3:statment4
I am still having problems with understanding ternary operator in Python.
Assignment statements support multiple targets:
>>> age = 10
>>> st, reject = ('Kid', True) if age < 10 else ('Adult', False)
>>> st, reject
('Adult', False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With