- 2
What is the use of NOT? In python?
2 Antworten
+ 2
x = 4
if not x == 5: -> means: if x is not equal to 5
print("Yes, x is not equal to 5")
# will print yes, because x is NOT equal to 5.
x = 5
if not x == 5:
print("Yes, x is not equal to 5")
# will print nothing, because x is equal to 5.
0
It's useful for functions that doesn't have negative form like "in".
if "e" in "hello":
print "e is in the word 'hello'"
if "x" not in "hello":
print "the letter x is not in 'hello'"
Both conditionals are true.