主页
Python
Python - 列表推导式
demo_list_comprehension_if_else
运行 ❯
×
更改方向
保存代码
更改主题
fruits = ["apple", "banana", "cherry", "kiwi", "mango"] newlist = [x if x != "banana" else "orange" for x in fruits] print(newlist)
['apple','orange','cherry','kiwi','mango']