2024-05-23 22:07:33 发布
网友
如果我的列表是
superheroes = [["Superman", "flying"], ["Spiderman", "web"], ["Batman", "Technology"], ["Wonder woman","Lasso of Truth"]]
就像你附加到任何列表一样:
superheroes += [["Green lantern","A green lantern..."]]
或者
superheroes.append(["Green lantern","A green lantern..."])
你可以这样做
temp = [] name = input("Enter Superhero's name") temp.append(name) type = input("Enter Superhero's type") temp.append(type) superheroes.append(temp)
这将要求用户输入超级英雄的名字和类型,并在现有列表中添加一个列表。
另一种方法是在一行中确定用户输入并更新列表:
superheroes.append([input("Enter superhero's name"),input("Enter superhero's type")])
就像你附加到任何列表一样:
或者
你可以这样做
这将要求用户输入超级英雄的名字和类型,并在现有列表中添加一个列表。
另一种方法是在一行中确定用户输入并更新列表:
相关问题 更多 >
编程相关推荐