Is there a substantial difference in Python 3.x between:
for each_line in data_file:
if each_line.find(":") != -1:
#placeholder for code
#more placeholder
and
for each_line in data:
if not each_line.find(":") == -1:
#placeholder for code
#more placeholder
My question isn't particular to the above usage, but is more general or essential - is this syntactical difference working in a different way, even though the result is the same? Is there a logical difference? Are there tasks where one is more appropriate or is this solely a stylistic difference? If this is merely stylistic, which one is considered cleaner by Python programmers?
Also, is the above an opposite instance of asking what the difference is between is
and ==
? Is the former, like the latter, a difference of object identity and object value equality? What I mean is, in my above example, is the is
in using not
implicit?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…