5.3 Logical Operators
47
>>> 5 == 5
True
>>> 5 == 6
False
True
and False are special values that belong to the type bool; they are not strings:
>>> type(True)
>>> type(False)
The == operator is one of the comparison operators; the others are:
x != y
# x is not equal to y
x > y
# x is greater than y
x < y
# x is less than y
x >= y
# x is greater than or equal to y
x <= y
# x is less than or equal to y
Although these operations are probably familiar to you, the Python symbols are
different from the mathematical symbols. A common error is to use a single equal
sign (=) instead of a double equal sign (==). Remember that = is an assignment
operator and == is a comparison operator. There is no such thing as =< or =>.
Chia sẻ với bạn bè của bạn: