三元指令

1.三元表达式举例:

a=1 if x=='hello' else 2

print(a,type(a))

2.三元表达之列表解析:

b=[i for i in range(10) if i<5]
print(b)

 3.列表解析中不能有四元,但可以有两元

原文地址:https://www.cnblogs.com/shengbei/p/9017325.html