What is relational in python?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Relational operators are used for comparing the values. It either returns True or False according to the condition. These operators are also known as Comparison Operators.

    Operator

    Description

    Syntax

    >

    Greater than: True if the left operand is greater than the right x > y

    <

    Less than: True if the left operand is less than the right x < y

    ==

    Equal to: True if both operands are equal x == y

    !=

    Not equal to – True if operands are not equal x != y

    >=

    Greater than or equal to: True if left operand is greater than or equal to the right x >= y

    <=

    Less than or equal to: True if left operand is less than or equal to the right x <= y

    Now Let’s see each RelationalOperator one by one.

    1) Greater than: This operator returns True if the left operand is greater than the right operand.

    Syntax:

    x > y
    

    Example:

    Python3

    Output:

    True
    

    2) Less than: This operator returns True if the left operand is less than the right operand.

    Syntax:

    x < y
    

    Example:

    Python3

    Output:

    False
    

    3) Equal to: This operator returns True if both the operands are equal i.e. if both the left and the right operand are equal to each other.

    Example:

    Python3

    Output:

    False
    

    4) Not equal to: This operator returns True if both the operands are not equal.

    Syntax:

    x != y
    

    Example:

    Python3

    Output:

    True
    

    5) Greater than or equal to: This operator returns True if the left operand is greater than or equal to the right operand.

    Syntax:

    x >= y
    

    Example:

    Python3

    Output:

    True
    

    6) Less than or equal to: This operator returns True if the left operand is less than or equal to the right operand.

    Syntax: 

    x <= y
    

    Example:

    Python3

    Output:

    False
    

    Relational operators are used to compare two variables.

    It will return true , if the comparison or relation is true.

    otherwise it will return false.




    Example

    OperatorDescriptionExample
    == Checks both left and right operands are same 10 == 10 it will return true.
    10 == 7 it will return false
    != Checks both left and right operands are not same. 10 != 20 it will return true.
    10 != 10 it will return false.
    < Checks whether the left operand is smaller than the right operand. 5 < 10 it will return true.
    10 < 10 it will return false.
    <= Checks whether the left operand is smaller than or equal to the right operand. 10 <= 10 it will return true
    20 <= 10 it will return false.
    > Checks whether the left operand is greater than the right operand. 50 > 10 it will return true
    5 > 10 it will return false.
    >= Checks whether the left operand is greater than or equal to the right operand. 10 >= 10 it will return true
    5 >= 10 it will return false.



    Relational Operators - Sample Program

    Example

    a = 5
    b = 10
    
    print(a == b)  #return False
    print(a != b)  #return True
    print(a < b)   #return True
    print(a <= b)  #return True
    print(a > b)   #return False
    print(a >= b)  #return False
    


    Relational operators are frequently used in decision making and looping statements. We will discuss about it in the future topics.


    Topics You Might Like

    What is the relational operator in python?

    Relational operators are used for comparing the values. It either returns True or False according to the condition. These operators are also known as Comparison Operators.

    What are relational operators in python give examples?

    The relational operators are also known as comparison operators, their main function is to return either a true or false based on the value of operands.

    What are the 6 relational operators in python?

    We have six of these, including and limited to- less than, greater than, less than or equal to, greater than or equal to, equal to, and not equal to. So, let's begin with the Python Comparison operators.

    What is the use of relational?

    The software used to store, manage, query, and retrieve data stored in a relational database is called a relational database management system (RDBMS). The RDBMS provides an interface between users and applications and the database, as well as administrative functions for managing data storage, access, and performance.