简体   繁体   中英

Python:Call a function from within another function

I have two functions, and I would like to call one function from the other.

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

Example would be

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

You can do the following:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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