📜  列表理解 python 代码示例

📅  最后修改于: 2022-03-11 14:46:26.242000             🧑  作者: Mango

代码示例6
# Make a List that contains the doubled values of a given list:

values = [2, 4, 6, 8, 10]
doubled_values = [x*2 for x in values]
print(doubled_values) # Outputs [4, 8, 12, 16, 20]

# You could achieve the same result like this:

values = [2, 4, 6, 8, 10]
doubled_values = []
for x in values:
    doubled_values.append(x*2)
print(doubled_values)