name = "alex"
res = "girl" if name == "alex" else "boy"
print(res)
#输出结果
girl
推导列表
egg = []
for i in range(10):
egg.append("鸡蛋 %s" % i)
print(egg)
l = ["鸡蛋 %s" % i for i in range(10)]
l1 = ["鸡蛋 %s" % i for i in range(10) if i>5]
print(l)
print(l1)
#输出结果
['鸡蛋 0', '鸡蛋 1', '鸡蛋 2', '鸡蛋 3', '鸡蛋 4', '鸡蛋 5', '鸡蛋 6', '鸡蛋 7', '鸡蛋 8', '鸡蛋 9']
['鸡蛋 0', '鸡蛋 1', '鸡蛋 2', '鸡蛋 3', '鸡蛋 4', '鸡蛋 5', '鸡蛋 6', '鸡蛋 7', '鸡蛋 8', '鸡蛋 9']
['鸡蛋 6', '鸡蛋 7', '鸡蛋 8', '鸡蛋 9']