Is there a logical difference between 'not ==' and '! = (Without)

Is there a significant 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 is not related to the above use, but is more general or significant - is this syntax difference working differently, although the result is the same? Is there a logical difference? Are there any problems when one of them is more appropriate or is it just a stylistic difference? If it's just a style, which one is considered cleaner by Python programmers?

, , is ==? , , ? , is not ?

+5
3

, ; , -, __ne__, ! =, __eq__, ==

, ,
not (a == b) __eq__ a, b - , not (a != b) __ne__ a, b - .

(! =)

+6

rich compare , == !=.

class EqTest(object):
    def __eq__(self, other):
        print "eq"
        return True
    def __ne__(self, other):
        print "ne"
        return False

a = EqTest()
b = EqTest()

print not (a == b)
# eq
# False
print a != b
# ne
# False

, , .

!= not == , .

+4

- find.

- . boolean not each_line.find(":") == -1.

In this context, where you want to use notit is when you have something that you can verify for truthfulness or falsehood.
For example, an empty string ''is set to False:

s = ''
if not s:
    print( is the empty string')

It seems you're a bit expressions identify authentication is, and is nota Boolean not.

An example of how you perform an identification test:

result_of_comparison = each_line.find(":") == -1
if result_of_comparison is False: # alternatively: is not True
    pass
+1
source

All Articles