How to compare two numbers in Python?
In Python, comparison operators can be used to compare the sizes of two numbers. These comparison operators include:
- greater than
- less than
- greater than or equal to
- less than or equal to
- equal to
- “!=” is not equal to”
Here is an example code comparing the sizes of two numbers:
a = 5
b = 10
if a > b:
print("a大于b")
elif a < b:
print("a小于b")
else:
print("a等于b")
The output shows that “a” is less than “b” because 5 is less than 10.