If One Line

alex23 wuwei23 at gmail.com
Thu Dec 25 18:46:00 EST 2014


On 26/12/2014 1:18 AM, JC wrote:
> Is it possible in python:
>
> if ((x = a(b,c)) == 'TRUE'):
> 	print x

One approach is to use a function in the condition to do the assignment:

     x = None

     def assign_to_x(val):
         global x
         x = val
         return val

     def a(x, y):
         return 'TRUE'

     b, c = 'foo', 'bar'

     if assign_to_x(a(b,c)) == 'TRUE':
         print(x)




More information about the Python-list mailing list