I want to declare variable name in sequence: Something like x_1, x_2, x_3,......., x_5 and assign value with them in python. Something like x_i = i^2.
n = 10
for i in range(1, n):
x_i = i**2
print(x_2)
Can someone please help?
I want to declare variable name in sequence: Something like x_1, x_2, x_3,......., x_5 and assign value with them in python. Something like x_i = i^2.
n = 10
for i in range(1, n):
x_i = i**2
print(x_2)
Can someone please help?
You could use this but its not recommended:
n = 10
for i in range(1, n):
globals()[f'x_{i}'] = i**2
print(x_2) #4