Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Python Comparison Operators

by suresh

Python Comparison Operators called Relational operators, and they are mostly used either in IF Statements or Python Loops. Comparison Operators in Python are usually used to check the relationship between two variables. If the relation is true, it returns TRUE, and if the relation is false, then it will return output as FALSE.

The below table shows all the Python Comparison Operators with examples.

Python Relational OperatorsUsageDescriptionExample
>a > ba is greater than b7 > 3 returns True (1)
<a < ba is less than b7 < 3 returns False (0)
>=a >= ba is greater than or equal to b7 >= 3 => True (1)
<=a <= ba is less than or equal to b7 <= 3 return False (0)
==a == ba is equal to b7 == 3 returns False (0)
!=a != ba is not equal to b7 != 3 returns True(1)

Python Comparison Operators Example

This example helps you to understand the Python Relational Operators practically. Here, we declared two variables a and b and their values are 9 and 4. Next, we are going to use these two variables to perform various comparison operations present in Python Programming

>>> a = 9
>>> b = 4
>>> print(" The Output of 9 > 4 is : ", a > b )
>>> print(" The Output of 9 < 4 is : ", a < b )
>>> print(" The Output of 9 <= 4 is : ", a <= b )
>>> print(" The Output of 9 >= 4 is : ", a >= b )
>>> print(" The Output of 9 Equal to 4 is : ", a == b )
>>> print(" The Output of 9 Not Equal To is : ", a != b )
Python Comparison Operators 1

We assigned 2 integer values a, b and we assigned the values 9 and 4.

>>> a = 9
>>> b = 4

In the next lines, We checked these values against each and every comparison operator (relational operator) present in Python Programming.

Use Python Comparison Operators in IF Statement

This example helps you to understand how Python Relational operators used in If statements. For this Python example, We use two variables x and y, and their values are 10 and 25.

Here, we are going to use these two variables in If Statement to check the conditions using one of the comparison operator present in python programming.

>>> x = 10
>>> y = 25
>>> if x >= y:
	print(" x value is Greater than or Equal to y ")
    else:
	print(" x value is Less than or Equal to y ")
Python Comparison Operators 2

In this Python realtional operator example, We assigned 2 integer values x, y, and assigned the values 10 and 25.

>>> x = 10
>>> y = 25

If Condition: If x is greater than or equal to y, then the first print statement will execute

print(" x value is Greater than or Equal to y ")

If the first condition fails, then the second print statement executes.

print(" x value is Less than or Equal to y ")

Here, 10 is neither greater nor equal to 25. So, the Second statement printed. Refer Python IF Statements and Python Loops.

Placed Under: Python

  • Download and Install Python
  • Python Arithmetic Operators
  • Python Assignment Operators
  • Python Bitwise Operators
  • Python Comparison Operators
  • Python Logical Operators
  • Python If Statement
  • Python If Else
  • Python Elif Statement
  • Python Nested If
  • Python For Loop
  • Python While Loop
  • Python Break
  • Python Continue
  • Python Dictionary
  • Python datetime
  • Python String
  • Python Set
  • Python Tuple
  • Python List
  • Python List Comprehensions
  • Python Lambda Function
  • Python Functions
  • Python Types of Functions
  • Python Iterator
  • Python File
  • Python Directory
  • Python Class
  • Python classmethod
  • Python Inheritance
  • Python Method Overriding
  • Python Static Method
  • Connect Python and SQL Server
  • Python SQL Create DB
  • Python SQL Select Top
  • Python SQL Where Clause
  • Python SQL Order By
  • Python SQL Select Statement
  • Python len Function
  • Python max Function
  • Python map Function
  • Python print Function
  • Python sort Function
  • Python range Function
  • Python zip Function
  • Python Math Functions
  • Python String Functions
  • Python List Functions
  • Python NumPy Array
  • NumPy Aggregate Functions
  • NumPy Arithmetic Operations
  • Python Numpy Bitwise operators
  • Numpy Comparison Operators
  • Numpy Exponential Functions
  • Python Numpy logical operators
  • Python numpy String Functions
  • NumPy Trigonometric Functions
  • Python random Array
  • Python numpy concatenate
  • Python numpy Array shape
  • Python pandas DataFrame
  • Pandas DataFrame plot
  • Python Series
  • Python matplotlib Histogram
  • Python matplotlib Scatter Plot
  • Python matplotlib Pie Chart
  • Python matplotlib Bar Chart
  • Python List Length
  • Python sort List Function
  • Python String Concatenation
  • Python String Length
  • Python substring
  • Python Programming Examples
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy