Comparison, relational operators, and logical operators

<1> comparison (i.e., the relationship) operator

python comparison operator in the following table

 

 

 

>>> # # relational operators 
... 
 >>> # == equal to: represent about two operands are equal, it is equal if the entire expression is True; are not equal False 
... num1 = 15 
num2 = 20 >>> 
>>> 
>>> Print (== num1 num2) 
False
 >>> 
>>> # ! = not equal 
... Print (num1! = num2) 
True
 >>> 
>>> # > greater than 
... Print (num1> num2) 
False
 >>> 
>>> # <less than 
... Print (num1 < num2)
True
>>> 
>>> # > = Greater than or equal to: num1 greater than or equal to num2, conditions are established 
... Print (num1> = num2) 
False
 >>> 
>>> # <= Less than or equal: num1 less than or equal to num2, are true 
... Print (num1 <= num2) 
True
 >>> 
>>> IF num1> = num2: 
...      Print ( " condition is satisfied! " ) 
...
 >>>
"" " 
== checks the value of two operands are equal, if the condition becomes true. As a = 3, b = 3, then (a == b) is True 
! = Value of two operands check are equal, if the values are not equal, the condition becomes true. as a = 1, b = 3, then (a! = b) is the true 
> check the value of the left operand is greater than right operand value, if so, the condition is satisfied. as a = 7, b = 3, then (a> b) is True 
<value check left operand is less than the value of the right operand, if it is, then the condition is satisfied. as a = 7, b = 3, (a <b) is False 
> = check that the value left operand is greater than or equal to right operand, if it is, then the condition is satisfied. as a = 3, b = 3, then (a> = b ) is True 
<= value check left operand is less than or equal to the value of the right operand, if it is, then the condition is satisfied. as a = 3, b = 3, then (a <= b) is True 
"" " 
# defines two variables 
A. 1 = 
B = 10 # RET = (A == B) 
# # == 
# # Analyzing 
# IF RET: 
#      Print ( "A is equal to b") 
# Analyzing 
# IF A == B:


#      Print ( "A equals B") 

# =! 
# IF A = B:! 
#      Print ( "A not equal to B") 

# > 
# IF A> B: 
#      Print ( "A greater than B") 

# <= 
IF A <= B:
     Print ( " A less B " )

<2> Logical Operators

 

 

>>> # # logical operators 
... 
 >>> # and: about expressions are True, the whole expression is the result was True 
... IF (==. 1. 1) and (10>. 3 ): 
.. .      Print ( " condition is satisfied! " ) 
... 
conditions are true! 

>>> # or: about expression has a True, the entire expression result is True 
... IF (1 == 2) or (10> 3 ): 
...      Print ( " condition is satisfied! " ) 
. .. 
condition is satisfied! 

>>> # not: the logical consequence of the right of expression is negated, Ture becomes False, False becomes True 
... not (1 == 2 ): 
...      Print ( " condition is satisfied! " ) 
... 
conditions are true! 

>>>
# Logical operators 
# and the 
# or or 
# not non- 

# and the 
# whole truth is really a fake is fake 
# website or app login requires the user to enter a user name and password -> ensure successful login must be a user name and password are correct 
# user_name = input ( "Please enter your user name:") 
# pass_wd = input ( "Please enter your password:") 
# # 12345 assume that the user name ADMIN 
# IF user_name == "ADMIN" and pass_wd == "12345": 
#      print ( "your successful login ...") 

# or or 
# fake a true full false is true then 
# website or app requires the user to enter the login user name and password -> whether the user to enter a user name or password error error 
# Tip: You enter the user name or password is incorrect ... 
# user_name = the iNPUT ( "Please enter your user name:") 
#pass_wd = input ( "Please enter your password:") 
# # # Suppose the user name ADMIN 12345 
# IF user_name = "ADMIN" or pass_wd = "12345":!! 
#      Print ( "user name or password you entered is incorrect. .. ") 

# not non- 
# neither true nor false is false is true 
flag = false
 # If the flag is false we print the HelloWorld 
# Print (flag == true) 
# IF flag == false: 
#      Print (" the HelloWorld ") 

IF  not Flag:
     Print ( " the HelloWorld " )

 

Guess you like

Origin www.cnblogs.com/kangwenju/p/12640019.html