what are the different context of != and not operator in real life problems | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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 Réponses
+ 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