Python comparison operators and logical operators

Source: Internet
Author: User
Tags logical operators

<1> compare (that is, relational) operators

The comparison operators in Python are the following table

operator Description Example
== Checks whether the values of the two operands are equal, and if so, the condition becomes true. If a=3,b=3 (a = = B) is true.
!= Checks whether the values of the two operands are equal, and if the values are not equal, the condition becomes true. True if a=1,b=3 (a! = b).
<> Checks whether the values of the two operands are equal, and if the values are not equal, the condition becomes true. True if A=1,b=3 (a <> b). This is similar to! = operator
> Checks if the value of the left operand is greater than the value of the right operand, and if so, the condition is true. True if A=7,b=3 (a > B).
< Checks if the value of the left operand is less than the value of the right operand, and if so, the condition is true. If A=7,b=3 (a < b) is false.
>= Checks whether the value of the left operand is greater than or equal to the value of the right operand, and if so, the condition is true. True if A=3,b=3 (a >= b).
<= Checks whether the value of the left operand is less than or equal to the value of the right operand, and if so, the condition is true. True if A=3,b=3 (a <= b).
<2> logical operators
operator Logical Expressions Description Example
and X and Y Boolean "and"-if x is False,x and y returns FALSE, otherwise it returns the computed value of Y. (A and B) returns 20.
Or X or Y Boolean "or"-if x is true, it returns true, otherwise it returns the computed value of Y. (A or B) returns 10.
Not Not X Boolean "Non"-returns False if X is True. If X is False, it returns TRUE. Not (A and B) returns False

Python comparison operators and logical operators

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.