是的,可以使用 'in' 运算符来查找列表中是否包含某个元素。例如:

my_list = [1, 2, 3, 4, 5]

if 3 in my_list:
    print('3 is in the list')

if 6 not in my_list:
    print('6 is not in the list')

输出:

3 is in the list
6 is not in the list

其中,'in' 运算符返回一个布尔值,表示元素是否在列表中。'not in' 运算符则返回相反的结果。

Python 列表中查找元素:使用 'in' 运算符

原文地址: https://www.cveoy.top/t/topic/ntAE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录