python - 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"))
解决方案
您可以执行以下操作:
def one_contains_another(word1, word2):
if first_contains_second(word1, word2) or first_contains_second(word2, word1):
return True
return False
推荐阅读
- angular - 从 v5.2 到 v6.1 而不是 v7.x 的 Angular 更新
- python - PYTHON2 失败的构建轮 PyAudio 和 PortAudio
- c# - 即使函数失败,也会创建输出 blob
- excel - Excel 宏循环 - 每列删除重复项
- ios - Xcode 10.1 在尝试将应用程序侧加载到带有 iOS 12.1 的设备后未能创建配置文件
- php - 使用 XmlReader 验证大型 XML
- sql - 表值参数可以是临时的吗
- javascript - 如何在节点中获取多个图像并在浏览器中显示
- r - 用列值内的条件按行排列 df
- python - 我的牌手排序功能仅按花色排序,而不是按价值排序。[Python]