Python in 关键字
示例
检查列表中是否包含 "banana"
fruits = ["apple", "banana", "cherry"]
if "banana" in fruits
print("yes")
自己试一试 »
定义和用法
The in
keyword has two purposes
The in
keyword is used to check if a value is present in a sequence (list, range, string etc.).
The in
keyword is also used to iterate through a sequence in a for
loop