This is such a basic thing, but I always got it wrong. So I created a reminder video for myself. Here, it’s very important to remember that the equals sign and Python is not the equals sign; it’s the assignment operator, because it assigns a value to a variable.
The single equals sign (=
) in Python is the assignment operator, which assigns a value on the right to a variable on the left. The double equals sign (==
) is the equality comparison operator, which checks if two values are equal.
Here’s a simple breakdown to reinforce your reminder:
=
(Assignment): This is an action. It’s like putting something into a box. For example,x = 5
means “put the value5
into the box namedx
.”==
(Comparison): This is a question. It’s like asking if two things are the same. For example,x == 5
asks, “Is the value in the boxx
equal to5
?” The answer is eitherTrue
orFalse
.
# == comparison operator (checks if the values of two operands are equal. It returns True if the values are the same and False otherwise.
# = Assignment operator. The assignment operator assigns a value to a variable, while the comparison operator is used to check for equality.
x = 5
y = 4
print(x == y)
Leave a Reply