List
从列表查找元素
方法1:
mylist = ['Garfield', 'Odie', 'Nelman']
if 'Odie' in mylist: # this is the best way
print 'yes'
else:
print 'no'
方法2:
use List.index(x)
, 但是当x不存在时会触发异常
从列表查找元素
方法1:
mylist = ['Garfield', 'Odie', 'Nelman']
if 'Odie' in mylist: # this is the best way
print 'yes'
else:
print 'no'
方法2:
use List.index(x)
, 但是当x不存在时会触发异常