In Python, comparison operators are used to compare values and return a Boolean value (True or False) based on whether the comparison is true or false.
The following are the comparison operators in Python:
In Python, comparison operators are used to compare two values and return a boolean value
(True or False) depending on the result of the comparison.
Python has six comparison operators in Python:
== (equal to): This operator checks if two values are equal and returns True if they are, otherwise, it returns False.
!= (not equal to): This operator checks if two values are not equal and returns True if they are not, otherwise, it returns False.
> (greater than): This operator checks if the left operand is greater than the right operand and returns True if it is, otherwise, it returns False.
< (less than): This operator checks if the left operand is less than the right operand and returns True if it is, otherwise, it returns False.
>= (greater than or equal to): This operator checks if the left operand is greater than or equal to the right operand. If it's true, it returns True otherwise, it returns False.
<= (less than or equal to): This operator checks if the left operand is less than or equal to the right operand. If it's true, it returns True otherwise, it returns False.
These comparison operators are used in conditional statements and loops to make decisions based on the result of the comparison.
Example:
# > operator
x = 5
y = 10
if x > y:
print("x is greater than y")
else:
print("x is not greater than y")
# OUTPUT: x is not greater than y
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In Python, comparison operators are used to compare values and return a Boolean value (True or False) based on whether the comparison is true or false.
The following are the comparison operators in Python:
In Python, comparison operators are used to compare two values and return a boolean value (True or False) depending on the result of the comparison.
Python has six comparison operators in Python:
These comparison operators are used in conditional statements and loops to make decisions based on the result of the comparison.
Example: