python - 如何简化 python 中的 if 条件?

标签 python if-statement conditional-statements simplify

我想知道是否有更简单的方法来编写 if 语句的条件。类似于 item1, item2 == "wood":。我目前有这段代码:

item1 = input("item1: ")
item2 = input("item2: ")

if item1 == "wood" and item2 == "wood":
    print("You created a stick")

最佳答案

这不是一笔巨大的节省,但您可以取出“木头”和

item1 = input("item1: ")
item2 = input("item2: ")

if item1 == item2 == "wood":
    print("You created a stick")

关于python - 如何简化 python 中的 if 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39761962/

相关文章:

python - 如何在 Windows 10 中使用 Selenium 和 Python 通过 Whatsapp Web 发送 pdf 文件

javascript - 如何在 PHP 的 while 循环中创建 if else 条件?

java - 字符类型的 if/else 语句

c - "if"函数在 C 中出现 "control may reach end of non-void function"错误

python - 将单词添加到 scikit-learn 的 CountVectorizer 的停止列表

python - 限制语句中的循环数量?

python - 使用 NaN 条件迭代数据帧

python - 条件正则表达式

python - 根据像素的颜色生成RGB图像的 bool 蒙版的最有效的方法是什么?

C++ If Then 不工作/停止