Python If Else Statement

Python supports standard logical conditions:

  • Equals: a == b
  • Not Equals: a != b
  • Less than: a < b
  • Greater than: a > b
  • Less than or equal to: a <= b
  • Greater than or equal to: a >= b

Conditions are used in “if statements” and loops:

a = 33
b = 200
if b > a:
    print("b is greater than a")
b is greater than a
a = 365
b = 365
if b > a:
    print("b is greater than a")
elif a == b:
    print("a and b are equal")
else:
    print("a is greater than b")
a and b are equal

As shown above, Python relies on indentation to define scope in the code.


Previous     Next

Use the Search Bar to find content on MarketingMind.