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:

  1. greater than
  2. less than
  3. greater than or equal to
  4. less than or equal to
  5. equal to
  6. “!=” 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.

bannerAds