Equality Operator #
Python comparison operators are used to compare two values and return a boolean value (True or False) based on the result of the comparison. The equality operator == (double qual signs) is used to compare the equality of two values or expressions.
For example:
x = 10 == 20
print(x) # Output: False
y = "David" == "David"
print(y) # Output: True
In the first example, the expression 10 == 20 evaluates to False, so x is assigned the value of False.
In the second example, the expression "David" == "David" evaluates to True, so y is assigned the value of True.
Exercise #
- Create a variable
equalto have the value ofTrueby using the equality operator==. - Create a variable
not_equalto have the value ofFalseby using the equality operator==.
Tests #
- Variable
equalshould beTrue - Variable
not_equalshould beFalse - Use the equality operator
==
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules