代码:的Python 3:在列表中找到字符串,返回字符串和NONE
def find(string_list, search):
new_list = []
for i in string_list:
if search in i:
new_list.append(i)
print(new_list)
print(find(['she', 'sells', 'sea', 'shells', 'on', 'the', 'sea-shore'], 'he'))
返回:
['she', 'shells', 'the']
None
默认返回值是'None'。从[print]中删除打印调用(find(...' –
列表打印在函数中,而None则不是函数的结果) – zhangyangyu