Is there a substantial difference in Python 3.x between:
for each_line in data_file:
if each_line.find(\":\") != -1:
#placeholder for code
Your first example is how you should be testing the result of find
.
Your second example is doing too much. It is additionally performing a boolean not on the result of the each_line.find(":") == -1
expression.
In this context, where you want to use not
is when you have something that you can test for truthiness or falsiness.
For example, the empty string ''
evaluates to False:
s = ''
if not s:
print('s is the empty string')
You seem to be conflating a little bit the identity-test expressions is
and is not
with the boolean not
.
An example of how you'd perform an identity test:
result_of_comparison = each_line.find(":") == -1
if result_of_comparison is False: # alternatively: is not True
pass