1 name = 'chen' 2 real_name = 'yuanyuan' if name == 'chen' else 'haha' 3 print(real_name) 4 #yuanyuan 5 6 #列表解析 7 egg_lists = ['鸡蛋%s' %i for i in range(5)] 8 print(egg_lists) 9 #['鸡蛋0', '鸡蛋1', '鸡蛋2', '鸡蛋3', '鸡蛋4'] 10 11 egg_lists = ['鸡蛋%s' %i for i in range(5) if i > 2] 12 print(egg_lists) 13 #['鸡蛋3', '鸡蛋4']