Heim  >  Artikel  >  Backend-Entwicklung  >  python中如何判断list中是否包含某个元素

python中如何判断list中是否包含某个元素

高洛峰
高洛峰Original
2016-10-17 11:34:341977Durchsuche

在python中可以通过in和not in关键字来判读一个list中是否包含一个元素

pythontab = ['p','y','t','h','o','n','t','a','b']
if 't' in pythontab:
    print 't in pythontab'
if 'w' not in pythontab:
    print 'w is not in pythontab'

in 和 not in 是非常常用的关键字。


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn