Python 或输入值的比较
这可能是个愚蠢的问题。我不是python最流利的人,但是我认为我对这项比较工作了解得足够多Python 或输入值的比较,python,Python,这可能是个愚蠢的问题。我不是python最流利的人,但是我认为我对这项比较工作了解得足够多 有人知道为什么当input=cloud时代码不工作吗?!?!?它与and一起工作,但为什么不与or一起工作?运算符或返回逻辑值。在代码中,compare等于True,因为字符串不是空的。将input转换为str是多余的 compareusr = str(input()) compare = "austin" or "cloud" if compare == compareusr: print("
有人知道为什么当input=cloud时代码不工作吗?!?!?它与and一起工作,但为什么不与or一起工作?运算符
或
返回逻辑值。在代码中,compare
等于True
,因为字符串不是空的。将input
转换为str
是多余的
compareusr = str(input())
compare = "austin" or "cloud"
if compare == compareusr:
print("it worked")
else:
print("it didnt work")
可能重复的
compare=“austin”或“cloud”
的可能重复与compare=“austin”
相同。在中创建一个列表并用检查条件。另外:在这种情况下,或
的功能可能与elvis操作符的功能相同。这意味着compare
等于“austin”
,因为它不是None
类型。
compareusr = input()
compare = ["austin", "cloud"]
if compareusr in compare:
print("it worked")
else:
print("it didnt work")