#How do i get "x" + i and print the variable's value?
print()
慕神8447489
浏览 131回答 3
3回答
神不在的星期二
如果要在不使用数组的情况下遍历编号变量,可以使用locals():x1 = 1x2 = 2x3 = 3for i in range(1,4): # Note that it's range(1,4) if you want 1, 2, 3 print(locals()[f"x{i}"])输出:123