我需要檢查列表長度的東西。也許這樣的事情,但是這並不工作:根據可能值列表檢查值
if len(list) != 1 or 2:
# Do something
if len(list) == 1 or 2:
# Do something different
好吧,我想通了這一點自己:
if len(list) == 1:
# Do something
elif len(list) == 2:
# Do the same something
if len(list) != 2:
# Do something different
elif len(list) != 1:
# Do something different
您是否需要將比較作爲範圍或可能的數字列表?如果它等於1,2,5或6,你會做些什麼嗎? – Hoopdady
不,只有一個號碼 – ComputerExpert69