Python relation and comparison operator


Relational Or Comparison Types Of Operators

The Relational or comparison operators are used for establishing some kind of relationship between the two operands. The relational operator is also known as the comparison operator because they are adopted to compare two operands on either side and manage their relationship. We can use this comparative operator along with the if, else, and while statements.
Relational or comparison types of operators are the basic bricks of a program that determines its functionality. Using this fundamental, you can decide the flow of code and what conditions need to be included to make sure the flow maintains that way.

The Precedence and Associativity of Relational Operators

Every relational operator has the corresponding precedence, and therefore it is necessary to view the associativity of these operators. The associativity is from left to right. It implies that the relational operator that displays first while reading an expression becomes evaluated first.

    ==    

    If the values of two values are equal, then the condition becomes true or the output false.

    <>    

        If the values of two values are not equal, then the condition becomes true.

    >    

        If the left value is greater than the value of the right operand, then the condition becomes true.

    <    

        If the left value is less than the value of the right operand, then the condition becomes true.

    >=    

        If the left value is greater than or equal to the value of the right operand, then the condition becomes true.

    <=    

        If the left value is less than or equal to the right value of the right, then the condition becomes true, or else it prints as false.

Example:

#Greater than or equal to x = 5 y = 3 print(x >= y) #Not equal x = 5 y = 3 print(x != y) #Greater than x = 5 y = 3 print(x > y) #Equal x = 5 y = 3 print(x == y)

OUTPUT:

True
True
True
False