jeudi 10 janvier 2019

Python 'in' operator with 'for' loop and with 'if' statement

I am using python in operator with for loop and with if statement. My question is how is in implemented, that it behaves differently in this two cases: it iterates when using for loop and it checks if some element exists when using with if statement? Does this depend on implementation of for and if?

    for i in x:
        #iterates

    if i in x:
        #checks weather i in x or not 

Aucun commentaire:

Enregistrer un commentaire