判断指定元素在列表中是否存在?
元素 in 列表名
元素 not in 列表名
列表元素的遍历
for 迭代变量 in 列表名:
操作
代码如下:
#打工人:朱乔栋
#革命尚未成功,同志仍需努力
print('p' in 'python') #True
print('k' not in 'python') #False
lst = [10,20,'python','hello']
print(10 in lst)
print(100 in lst)
print(10 not in lst)
print(100 not in lst)
print('------------------')
for item in lst: #目前我们学过的迭代对象有列表,字符串
print(item)
运行结果:
True
True
True
False
False
True
------------------
10
20
python
hello
Process finished with exit code 0