简体   繁体   English

仅在满足两个条件时才满足的 if 语句 - Python

[英]If statement that only satisfies when both conditions are met - Python

I'm trying to figure out the issue with this code.我试图找出这段代码的问题。 I'm coding in python.我正在用python编码。 I want my condition to fail only when both statements are inside an array.我希望我的条件仅在两个语句都在数组中时才失败。 Otherwise, I'm looking for this code to pass and print "Enter".否则,我正在寻找此代码以通过并打印“Enter”。

edge1 = []
edge2 = []
edge1.append("hello")
edge2.append("world")

if ("hello" not in edge1 and "bye" not in edge2):
    print("entered")

Expected output: "entered"预期输出:“进入”

Since you said, "I want my condition to fail only when both statements are inside an array."既然你说,“我希望我的条件只有当两个语句都在一个数组中时才会失败。”

Your 'if' condition should be like following您的“如果”条件应如下所示

if (not ( "hello" in edge1 and "bye" in edge2)):
    print("entered")

ie 'not' should be applied to the final outcome即“不是”应该应用于最终结果

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

相关问题 即使满足条件,Python if 语句也会不断给出 else 输出 - Python if statement keeps giving else output even when conditions are met Python,但似乎满足条件但无法识别语句 - Python if statement not recognized though conditions appear to be met Python 脚本:仅在不满足所有条件时提取 - Python Script: Extract Only if All Conditions Are Not Met Discord py:为什么必须满足 2 个条件而只满足 1 个条件? - Discord py: Why are 2 conditions met when only 1 must be met? 满足条件时,Python while循环不会中断 - Python while loop not breaking when conditions are met 在python中不满足条件时不创建对象? - Not creating an object when conditions are not met in python? 当两个条件都满足时,如何使 Discord Bot 响应? - How to make a Discord Bot respond when two conditions are both met? Python 循环 function 仅在 Dataframe 中的行中满足条件时提取第一列名称 - Python Loop function to extract first column name only when conditions are met in row in Dataframe Python:即使条件未满足,在if语句中使用“或”也会导致代码执行 - Python: using 'or' in an if statement causes code to execute even if conditions were not met 满足条件时不执行第三个 ELIF 语句。 在我重新运行代码后执行。 Python - Third ELIF statement doesn't execute when conditions are met. Executes after I re run code. Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM