The following codes are from "Learning Python(5E)" P545. I am a little bit confused with the indentation. From the codes, I thought the else-statement should be linked with the first if-statement rather than the second one. However, from the output, it seems it is linked with the second one. Did I miss something from if-else-statement indentation? Thank you!
def intersect (*args):
res = []
for x in args[0]:
if x in res:continue
for other in args[1:]:
if x not in other:
break
*# which if-statement does the following "else" belong to?*
else:
res.append(x)
return res
Aucun commentaire:
Enregistrer un commentaire