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
Following is the syntax of Python Equal Comparison Operator.
result = operand_1 == operand_2
operand_2 are values of any datatype. Equal operator returns true if
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
a = 10 b = 12 c = 12 print(a == b) print(b == c)
Example 2: Equal Operator with IF Statement
In the following example, we shall use equal operator in IF condition.
a = 10 if a%2 == 0 : print(a, "is even number.")
10 is even number.
a%2 == 0 returns true for
Example 3: Equal Operator with Strings
In this example, we shall use Equal Operator to check if two strings are equal.
a = "python" b = "python" if a == b : print("a and b have same value.")
a and b have same value.
Example 4: Equal Operator in While Condition
You can use equal operator in while loop condition.
a = 20 while int(a/6) == 3: print("hello") a += 1
hello hello hello hello
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.