I m fairly new to python and have found that I need to query a list about whether it contains a certain item.
The majority of the postings I have seen on various websites (including this similar stackoverflow question) have all suggested something along the lines of
for i in list
if i == thingIAmLookingFor
return True
然而,我也从一个论坛发现:
if thingIAmLookingFor in list
# do work
工作。
我很想知道,<代码>如果在清单编码>方法中为<代码>()中的一,或者该编码是否得到不同执行。
我也希望,如果是这样的话,我更愿意这样做。