how to dynamically create variables in python code example
Example 1: Dynamic Variable declaration in Python
user_input = raw_input("Enter a variable name : ")
Enter a variable name: number
globals()[user_input] = 25
Class Table:
def __init__(self,x,y,datalist):
for i in range (x):
for j in range (y):
var = f'table{i}_{j}'
locals()[var] = datalist[i][j]
Example 2: creating dynamic variable in python
for i in range(0, 9):
globals()[f"my_variable{i}"] = f"Hello from variable number {i}!"
print(my_variable3)