-1
這裏是我的意思是:如何將原始輸入字符串值轉換爲與Python 2中原始輸入相同名稱的變量的值?
foo = 25
bar = (raw_input("foobar: "))
print bar
如果「foo」被用作輸入,我想它打印25,而不是「富」。這可能嗎?我怎樣才能做到這一點?
(我目前在Python 2.工作)
這裏是我的意思是:如何將原始輸入字符串值轉換爲與Python 2中原始輸入相同名稱的變量的值?
foo = 25
bar = (raw_input("foobar: "))
print bar
如果「foo」被用作輸入,我想它打印25,而不是「富」。這可能嗎?我怎樣才能做到這一點?
(我目前在Python 2.工作)
使用eval()命令:
foo = 25
bar = eval(raw_input("enter 'foo': "))
print (bar)
你可以使用字典.....'X = { '富': 25} print(x [bar])' – depperm