Learning Python: Conditions

IF

a = 10
b = 100
if a > b:
    print("a {0} is greater than b {1}".format(a, b))

IF .. ELIF

c = 20
if a > b:
    print("a {0} is greater than b {1}".format(a, b))
elif b > c:
    print("b {0} is greater than c {1}".format(b, c))

IF .. ELSE

if a > b:
    print("a {0} is greater than b {1}".format(a, b))
else:
    print("Whatever")

IF with no statement … err

b = 2
if c > b:
print("c {0} is greater than b {1}".format(c, b))
print("BOO BOO!")

short hand if … else

print("Short hand A") if a > b else print("B")
print("Short hand A") if a < b else print("Short Hand B")

and condition

a = 1000
a = int(100)
a = "Abc"
a = "1"
a = int("1")


if a > b and a > c:
    print("A [{0}] is bigger than B [{1}] and C[{2}]".format(a, b, c))
# and condition
a = 5
if a > b or a < c:
    print("A [{0}] is bigger than B [{1}] or a is less than C[{2}]".format(a, b, c))

Python Conditions and if statements Equals: a == b Not Equals: a != b Less than: a < b Greater than: a > b Greater than or equal to: a >= b