Forming Simple Conditions

Relational Operators and Expressions

In [14]:
import random
a = random.choices(range(100), k=1)[0]
b = random.choices(range(100), k=1)[0]
print("a is {0} and b is {1}".format(a, b))

print("a < b ->", a < b)
print("a <= b ->", a <= b)
print("a != b ->", a != b)
a is 12 and b is 79
a < b -> True
a <= b -> True
a != b -> True
In [17]:
a = random.choices(range(100), k=1)[0]
b = random.choices(range(100), k=20)
print("a is {0} and b is {1}".format(a, b))

print("a in b", a in b)
print("a not in b", a not in b)
a is 33 and b is [60, 27, 69, 77, 54, 25, 31, 42, 66, 78, 8, 89, 18, 47, 41, 30, 79, 6, 30, 40]
a in b False
a not in b True

Boolean Data Type

In [23]:
val = True
print(val)
print(type(val))
True
<class 'bool'>
In [24]:
10 < 23
Out[24]:
True

Comparison Data Types

In [27]:
"aaaa" < "bbbb"
Out[27]:
True
In [28]:
"aaaa" < "Bbbb"
Out[28]:
False
In [ ]: