在python中将用户输入指定为列表的名称(Assign user input as name for a list in python)

编程入门 行业动态 更新时间:2024-10-27 22:30:20
在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 ", UserListName

wouldn't that just read the input only and not display it in list form?

最满意答案

刚想出最后一行应如下所示,以包括用户输入

print "The user list name is ", MyList

Just figured out that the last line should read as follows to include user entry

print "The user list name is ", MyList

更多推荐

本文发布于:2023-08-08 00:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   名称   用户   列表   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!