, . search_term, for x in y x y. , for x in [1, 2, 3], x = 1 .. , , 'a' == 'b', , '==' a ', , , !
-
x in list
True False, x ! ( "list", , ).
, Pythonic
def search_for_string(a_list, search_term):
if search_term in a_list:
return 'string found!'
elif not a_list:
return 'empty list!'
else:
return 'string not found!'
, bool([]) False, , .
-, , , .
def search_for_string(a_list, search_term):
for index, item in enumerate(a_list):
if a_list[index] == search_term:
return 'string found!'
elif len(a_list) == 0:
return 'string not found'
else:
continue
return 'string not found2'