首页 > 解决方案 > Python:从另一个函数中调用一个函数

问题描述

我有两个函数,我想调用另一个函数。

def first_contains_second(word1, word2):
    if word1 in word2:
        return True
    return False

def one_contains_another(word1, word2):
    if word1 in word2 or word2 in word1:
        return True
    return False

例子是

print(first_contains_second("apple", "ppl"))
print(one_contains_another("ppl", "apple"))

标签: pythonfunction

解决方案


您可以执行以下操作:

def one_contains_another(word1, word2):
    if first_contains_second(word1, word2) or first_contains_second(word2, word1):
        return True
    return False

推荐阅读