简体   繁体   English

Python 字符串和子字符串

[英]Python strings and substrings

I have to write a Python function that takes a list of strings as its argument.我必须编写一个 Python function ,它将字符串列表作为其参数。 The function should then print those strings in the list that contain as substrings either "cat" or "dog".然后 function 应打印列表中包含“cat”或“dog”作为子字符串的那些字符串。

This is the code I have but nothing comes up when I run the code in Python:这是我拥有的代码,但是当我在 Python 中运行代码时什么都没有出现:

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

You just have some indentation issues.你只是有一些缩进问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM