我正在学习Python,而且我已经陷入了我所制作的示例代码中。
from random import *
items = ["high", "low"]
quantity = sample(items, 1) # Pick 1 random items from the list
def start():
if quantity == "high":
print ("Quantity is high")
else:
print ("Quantity is low")
start()
我总是得到“数量很少”,但如果我使用“数量很大”,就像这样:
def start():
if "high" in quantity:
print ("Quantity is high")
else:
print ("Quantity is low")
然后是对的。我不知道为什么==不起作用。谢谢!