lundi 19 février 2018

Execution for-loop in Python

def search_for_element(L, char):
    for i in L:
        if i == char:
            return True
        else:
            return False

When I run the function, it only outputs one statement on the screen. So why is the for loop only executed once?

Aucun commentaire:

Enregistrer un commentaire