Python 判断字符串是否在列表中
可以使用 'in' 关键字来判断一个字符串是否在列表中。
示例如下:
string = 'hello'
string_list = ['hello', 'world', 'python']
if string in string_list:
print('字符串存在于列表中')
else:
print('字符串不存在于列表中')
输出结果为:'字符串存在于列表中'。
原文地址: https://www.cveoy.top/t/topic/qjz5 著作权归作者所有。请勿转载和采集!