Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python字符串和子字符串_Python_String_Function_Arguments_Substring - Fatal编程技术网

Python字符串和子字符串

Python字符串和子字符串,python,string,function,arguments,substring,Python,String,Function,Arguments,Substring,我必须编写一个Python函数,它以字符串列表作为参数。然后,函数应打印列表中包含“cat”或“dog”子字符串的字符串 这是我所拥有的代码,但在Python中运行代码时,什么都没有出现: def check_string(string_list): for word in string_list: if "cat" in word or "dog" in word: print(word) 您只是有一些缩进问题 def检查

我必须编写一个Python函数,它以字符串列表作为参数。然后,函数应打印列表中包含“cat”或“dog”子字符串的字符串

这是我所拥有的代码,但在Python中运行代码时,什么都没有出现:

def check_string(string_list):
    for word in string_list:
       if "cat" in word or "dog" in word:
    print(word)

您只是有一些缩进问题

def检查字符串(字符串列表):
对于字符串列表中的单词:
如果单词中有“猫”或“狗”:
打印(word)

在哪里(用什么)调用该函数?似乎打印错误。它应该是If声明的一部分。请更正,并尝试用适当的例子发布问题。