what are the different context of != and not operator in real life problems | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what are the different context of != and not operator in real life problems

!= and not operator

14th Apr 2019, 8:53 PM
clovert
clovert - avatar
3 Answers
+ 9
# Specify a language in Relevant Tags to narrow down question scope. I'm proposing an answer in Python because I see from your profile that you are learning it. # The `!=` operator is used to compare values of its operands. It returns a boolean state, True when both operands' values equals, False otherwise. a, b = 1, 2 print("a == b ->", a == b) # `==` operator tests for equality print("a != b ->", a != b) # `!=` operator tests for inequality # The `not` operator returns an inverted logical expression. # It returns True when the given operand was False; otherwise it return False when the given operand was True. # It only accepts one operand to work. # Basically, this is a logical operator, so its operand ideally should be something that can be evaluated as boolean expression. young = True print("young ->", young, "not young ->", not young) if not young: print("You are old") else: print("You are young") Hth, cmiiw
15th Apr 2019, 6:02 AM
Ipang
+ 3
Ipang couldnt have done a better job myself
15th Apr 2019, 11:41 PM
Logomonic Learning
Logomonic Learning - avatar
+ 3
(A) 'Not equal to’ vs. (B) ‘Not true’ Examples: (A) sky = “dark” if sky != “light” then sun = 0 (B) sun = 0 if not sun then sky = “dark” In (A), you compare the value of sky to the value “light”. If those two values are not equal, then you proceed with the action. In (B), you check whether the expression sun is true. If that expression is not true, then you proceed with the action. Combined Example: sky = “dark” sun = 1 if not sun or sky != “light” then lamp_flag = 1 In that example, the expression not sun is false, but the second condition is true, so the action occurs.
3rd Oct 2019, 7:36 PM
u007
u007 - avatar