我正在打印列表中剩余的项目。在
我想让用户输入他在哪里:乌得勒支(这是例如项目5,如果它匹配,打印列表中剩余的站点(例如:好的,第6项、第7项等是剩余的站点)。我试过切片,但这不是我真正想要的,或者我试错了。我可以使用哪个函数来执行此操作?在
到目前为止:
station = ['Utrecht', 'Amsterdam', 'Zwolle', 'Groningen','Leeuwarden']
vraag = input("Where are you?")
while station == vraag:
Tags:
输出:
^{pr2}$首先,检查列表中是否存在该值,如果成功找到索引。在
最后,由于列表索引包含在“:”之前,所以应该使用(value+1)
虽然我没有使用过3.4.3,但是在python3.4中,您可以使用一个普通的for循环来迭代它,因为它返回一个生成器。在
^{pr2}$如何进行末端检查:
这是密码。只需从用户输入中找到索引并使用切片
相关问题 更多 >
编程相关推荐