Is there method by using python if/else (ternary_operator) to achieve this function:
flag = True # or False
if flag:
print 'abc'
else:
pass
I tried to using:
print 'abc' if flag else ''
But a blank line will be print if the flag == False
. Because:
print 'abc' if flag else ''
== print ('abc' if flag else '')
Is there any way can make print nothing if flag == False
without using ;
?
Thanks in advance.
By the way, I'v tried using lambda
, but it wasn't successful, here my code:
a = lambda x: x if False else None
print a(1)
Result:
>> python a.py
None