如何检查输入是否在python的列表中? [英] How do I check if an input is in a list in python?

查看:355
本文介绍了如何检查输入是否在python的列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够输入一个值并检查它是否在列表中,然后再在列表中运行所需的其余程序.

I want to be able to enter a value and check if it is in a list and if it is then in the list run a the rest of the program wanted.

a=input('enter value')
b=(1,2,3,4)
c=(5,6,7,8,9)
if a is in b:
   print 'enter in code thats wanted'

推荐答案

您几乎完全自己写了它,而不是-

You've written it yourself almost correctly, just instead of -

if a is in b:

应该是-

if a in b:

这篇关于如何检查输入是否在python的列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆