Python:for循环变量,如何分配给它们?

Wag*_*eda -10 python

我不知道如何循环变量,为它们赋值。

a = 1; b = 2; c = 3 
for x in [a, b, c]:
  print(x)

1
2
3

for x in [a, b, c]:
  x = x * 2

for x in [a, b, c]:
  print(x)

1
2
3
Run Code Online (Sandbox Code Playgroud)

Jam*_*ner 5

您可以使用列表理解和元组拆包。

a = 1
b = 2
c = 3

a, b, c = [i * 2 for i in [a, b, c]]

print(a, b, c)
# 2 4 6
Run Code Online (Sandbox Code Playgroud)