检查项目是一个数组 [英] Check if item is in an array
本文介绍了检查项目是一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个字符串数组,我可以检查一个字符串是否在数组中不执行为
循环?具体来说,我正在寻找一种方法来一个如果
语句中做到这一点,所以像这样的:
如果[检查项目在阵列]:
解决方案
假设你的意思是清单里你说阵,你可以做
如果my_list项目:
# 随你
If I've got an array of strings, can I check to see if a string is in the array without doing a for
loop? Specifically, I'm looking for a way to do it within an if
statement, so something like this:
if [check that item is in array]:
解决方案
Assuming you mean "list" where you say "array", you can do
if item in my_list:
# whatever
这篇关于检查项目是一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文