Python字符串和子字符串

问题描述

我必须编写一个以字符串列表作为参数的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 check_string(string_list):
    for word in string_list:
       if "cat" in word or "dog" in word:
            print(word)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...