Contents
Python Equal – Comparison Operator
Python Equal is a Comparison Operator used to check if two values are equal.
The symbol used for Python Equal operator is ==.
Equal Operator is mostly used in boolean expressions of conditional statements like If, If-Else, Elif, While, etc.
Syntax
Following is the syntax of Python Equal Comparison Operator.
result = operand_1 == operand_2
where operand_1 and operand_2 are values of any datatype. Equal operator returns true if operand_1 and operand_2 are equal values, else it returns false.
Example 1: Equal Comparison Operator
In this example, we shall take two integers, and check if they are equal using ==.
Output
False
True
Example 2: Equal Operator with IF Statement
In the following example, we shall use equal operator in IF condition.
Output
10 is even number.
a%2 == 0 returns true for a=10.
Example 3: Equal Operator with Strings
In this example, we shall use Equal Operator to check if two strings are equal.
Python Program
a = "python"
b = "python"
if a == b :
print("a and b have same value.")
Run Code CopyOutput
a and b have same value.
Example 4: Equal Operator in While Condition
You can use equal operator in while loop condition.
Output
hello
hello
hello
hello
Summary
In this tutorial of Python Examples, we learned what Python Equal Comparison Operator is, how to use it to find if two values are equal, with the help of well detailed example programs.