<分区>
我正在使用 python,想知道是否可以向用户询问变量的名称,然后使用该名称创建一个变量。例如:
my_name = input("Enter a variable name") #for example the user could input orange
#code to set the value of my_name as a variable, say set it to the integer 5
print(orange) #should print 5 if the user entered orange
我知道可以使用字典来完成,但我想知道这是否可以在不创建额外对象的情况下实现。我正在使用 python 3。谢谢。