Comparison Operators


In [17]:
x = 5
y = 10

In [18]:
#greater than
print 'Is x > 10 ? : {v}'.format (v = x>10)
#less than
print 'Is x < 10 ? : {v}'.format (v = x<10)
#equal
print 'Is x == 10 ? : {v}'.format (v = x==10)
#not equal
print 'Is x != 10 ? : {v}'.format (v = x!=10)
print 'Is x != 10 ? : {v}'.format (v = x<>10)
#greater than or equal
print 'Is x >= 10 ? : {v}'.format (v = x>=10)
#less than or equal
print 'Is x <= 10 ? : {v}'.format (v = x<=10)


Is x > 10 ? : False
Is x < 10 ? : True
Is x == 10 ? : False
Is x != 10 ? : True
Is x != 10 ? : True
Is x >= 10 ? : False
Is x <= 10 ? : True

In [21]:
# Multiple comparison 
# And
print 'Is x < 10 and x>0 ? : {v}'.format (v = x<10 and x>0)
print 'Is x < 10 and x>0 ? : {v}'.format (v = 10>x>0)

# Or
print 'Is x < 10 or x>0 ? : {v}'.format (v = x<10 or x>0)


Is x < 10 and x>0 ? : True
Is x < 10 and x>0 ? : True
Is x < 10 or x>0 ? : True

In [ ]: