在python中将用户输入指定为列表的名称(Assign user input as name for a list in python)
此问题可能与“ 将用户输入转换为列表名称 ”重复。 但我想弄清楚的是为什么最后一行代码不打印用户的条目?
MyList = {} UserListName = raw_input("Insert List Name") MyList[UserListName]=[] print "The user list name is ", MyList[UserListName]它最终打印“用户列表名称是[]”虽然我期待“用户列表名称是JohnsList”。 如果它读
print "The user list name is ", UserListName不会只是读取输入而不是以列表形式显示它?
This question may be a duplicate of "Convert User Input into a List Name". But what I am trying figure out is why does the last line of code not print the user's entry?
MyList = {} UserListName = raw_input("Insert List Name") MyList[UserListName]=[] print "The user list name is ", MyList[UserListName]It ends up printing "The user list name is []" though I am expecting "The user list name is JohnsList". If it read
print "The user list name is ", UserListNamewouldn't that just read the input only and not display it in list form?
最满意答案
刚想出最后一行应如下所示,以包括用户输入
print "The user list name is ", MyListJust figured out that the last line should read as follows to include user entry
print "The user list name is ", MyList更多推荐
发布评论