繁体   English   中英

Python:从另一个函数中调用一个函数

[英]Python:Call a function from within another function

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

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"))

您可以执行以下操作:

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

您可以使用装饰器,查看此链接

暂无
暂无

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

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