Python 3.x 有办法吗?

Python 3.x 有办法吗?,python-3.x,Python 3.x,搜索时间:/ x0,x1,x2=1,2,3 for i in range(3): xi=xi+1 print(x1,x2,x3) >2 3 4 使用“for”方法有没有办法做到这一点?使用列表按索引访问项目: x = [1,2,3] for i, item in enumerate(x): # Enumerate will give the index and item at that index x[i] = item + 1 或者更像C: for i in r

搜索时间:/

x0,x1,x2=1,2,3
for i in range(3):
    xi=xi+1
print(x1,x2,x3)
>2 3 4

使用“for”方法有没有办法做到这一点?

使用列表按索引访问项目:

x = [1,2,3]
for i, item in enumerate(x):    # Enumerate will give the index and item at that index
    x[i] = item + 1
或者更像C:

for i in range(length(x)):    # Go over the whole list
    x[i] = x[i] + 1           # Also x[i] += 1

根据Rocket Hazmat的评论,使用列表而不是3个单独的变量来存储您的值。这也将解决您不能称为“xi”的问题,因为这并不存在

大概是这样的:

values = [1,2,3]
for i in range(3):
    values[i] = values[i] + 1

它已经在使用中。你是什么意思?我的意思是它不起作用,因为它前面的xi不存在我的问题是,有没有办法让它起作用,使用xi调用x1,然后调用x2,x3…使用一个列表,而不是3个单独的变量。啊,我错过了,现在得到了问题,或者你可以使用3个列表。x=[1],y=[2],z=[3]OP要求实现使用for,但是noice:Dah,然后它的
x,y,z=[i+1 for i in x,y,z]
Ho sweet它不使用列表谢谢!!!我可以通过使用这个NICE来克服,但是使用列表对我来说是有问题的(内存)@GabrielT为什么内存有问题?
x=1
y=2
z=3
x,y,z = map(lambda i: i+1, [x,y,z])