Python“in”运算符与“for”循环和“if”语句

Nan*_*ane 5 python if-statement for-in-loop

我在for循环和if语句中使用 python in运算符。我的问题是如何实现的,在这两种情况下它的行为不同:它在使用for循环时进行迭代,并在使用if语句时检查某些元素是否存在?这是否取决于for和if的实现?

    for i in x:
        #iterates

    if i in x:
        #checks weather i in x or not 
Run Code Online (Sandbox Code Playgroud)