一句话赋值型的条件表达式,python里面的实现方式比较可读。假如设置一个flag,如果condition成立则flag=True,否则flag=False。python实现如下:
flag = True if [condition] else False
例如如果list不为空,flag为True:
flag = True if len(list)>0 else False
一句话赋值型的条件表达式,python里面的实现方式比较可读。假如设置一个flag,如果condition成立则flag=True,否则flag=False。python实现如下:
flag = True if [condition] else False
例如如果list不为空,flag为True:
flag = True if len(list)>0 else False
转载于:https://my.oschina.net/i33/blog/151365