0

what's the difference between "not" and "!=" ???

if not 1 == 1: print("hehe") #is the same to make if 1 != 1: print("hehe") #right?

5th May 2019, 11:27 PM
Lucho 23
Lucho 23 - avatar
1 Odpowiedź
+ 5
The result will be same for builtins but if you create your own class and implement __eq__ and __ne__ differently, you can get different results class A: def __init__(self, a): self.a = a def __eq__(self, other): return self.a == other.a def __ne__(self, other): return self is not other a1 = A(5) a2 = A(5) print(not a1 == a2) #False print(a1 != a2) #True
6th May 2019, 12:12 AM
Mert Yazıcı
Mert Yazıcı - avatar