Python 檢查列表項是否存在
檢查列表項是否存在
要確定列表中是否存在指定項,請使用 in
關鍵字
示例
檢查“apple”是否存在於列表中
thislist = ["apple", "banana", "cherry"]
如果 "apple" 在 thislist 中
print("是的,'apple' 在水果列表中")
自己動手試一試 »
要確定列表中是否存在指定項,請使用 in
關鍵字
檢查“apple”是否存在於列表中
thislist = ["apple", "banana", "cherry"]
如果 "apple" 在 thislist 中
print("是的,'apple' 在水果列表中")
自己動手試一試 »
如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com
如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com