实验嵌套的元组。:为什么这说这是太多的变量?
目前,我正在阅读有关嵌套元素的信息,并尝试了一个非常简单的元素。有人可以指出我出错的地方吗?
albums = ("Backstreet Boys", "1991",
[("No place"), ("Backstreet's Back"), ("Everybody")])
for artist,year,songs in albums:
print("Artist: {}\nYear:{}\nSongs: {}".format((artist,year,songs)))
感谢您的帮助,大家。 :)
I'm reading about nested tuples at the moment and trying a very simple one. Can someone point out to where I'm going wrong?
albums = ("Backstreet Boys", "1991",
[("No place"), ("Backstreet's Back"), ("Everybody")])
for artist,year,songs in albums:
print("Artist: {}\nYear:{}\nSongs: {}".format((artist,year,songs)))
Thanks for the help, everyone. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将专辑元组包裹在列表中,然后在格式命令中删除括号。
那是因为Xou尝试通过元组专辑迭代,而不是元组列表。
You need to wrap the albums tuple in a list and remove the brackets in the format command.
That is because xou try to iterate through the tuple albums, not a list of tuples.