Boolean Operations

In Python, a boolean is a variable that can only be two values: True or False. Numbers can also represent a boolean, where 0 is False and any other number is True. There are several operators used in Python to compare values that evaluate to booleans. The following are examples of this feature, all of which return boolean values. print 3 < 4; # This will print True because 3 is less then 4 print 3 == 3; # True print 3 == 10; # False print 5 <= 5; # True print 5 < 5; # True print 10 != 9; # True print 5 == True; # True print 0 == False; # True print 0 == True; # False
 * < (less than)
 * > (greater than)
 * <= (less than or equal to)
 * >= (greater than or equal to)
 * != (does not equal)
 * == (equal to)
 * 1) Examples

Is variable x contained in y?
The keyword "in" can be used to check whether an item is contained within a list, tuple, or string and returning a boolean: #Using lists a = [1,4,1000,99] b = 1000 c = b in a # c is True because 1000 is in the list #Using strings a = "Hello World" b = "Hello" c = b in a # c is True because "Hello" is in "Hello World"