>>> 5 > 6 False >>> # and, or, not >>> #** not >>> x = 5 >>> y = 6 >>> x == y False >>> not x ==y True >>> y > x True >>> not y > x False >>> y <= x False >>> x != 5 False >>> not x == 5 False >>> #and >>> (x == 5) and (y == 6) True >>> (x == 5) and (y == 5) False >>> True and False False >>> # or >>> True or True True >>> True or False True >>> False or True True >>> False or False False >>> #in english, 'or' is often different >>> #I'm going to eat a bagel or a bun >>> #usually False if you eat both >>> #but True or True is True >>> tall = True >>> woman = True >>> short = False >>> man = False >>> tall and woman True >>> tall or woman True >>> tall or short True >>> man or woman True >>> short or man False >>> True or False True # Note: the predefined value is False, with # a capital letter >>> (False or True) and (false or True) Traceback (most recent call last): File "", line 1, in (False or True) and (false or True) NameError: name 'false' is not defined >>> (False or True) and (False or True) True >>> False == 0 True >>> True == 1 True # All non-0 numbers are treated as True; 0 is treated as False >>> if 43: print('yes') yes >>> if 43: print('yes') yes >>> if -1: print('yes') yes >>> if 0: print('yes') # Same for strings; the empty string is False # any other string is True >>> if '': print('yes') >>> if "hello": print('yes') yes >>> # all the operators - comparisons and >>> # and and or: each instance takes two >>> # arguments >>> num = 6 >>> if num == 10 or 20 or 30: print("yes") else: print("no") yes >>> #the same as False or True or True >>> # >>> #New topic: lazy evaluation >>> False and True False >>> (x > 10) and (y == 6) False >>> True or False True >>> # end of the logic stuff for today >>> #more about strings >>> 'cs401' 'cs401' >>> "cs401" 'cs401' >>> 'cs401" SyntaxError: EOL while scanning string literal >>> 'cs' + '401' 'cs401' >>> '401' + 'cs' '401cs' >>> int('401') 401 >>> "Tigers are " + "fun" * 4 'Tigers are funfunfunfun' >>> "Bwa" + 'ha' * 3 'Bwahahaha' >>> for i in range(3,8): print(i) 3 4 5 6 7 >>> for i in [2,3,4,5]: print(i) 2 3 4 5 >>> for i in "hello": print(i) h e l l o >>> # in is a test with strings >>> if 'e' in 'hello': print('yes') yes >>> if 3 in [2,3,4,5,6]: print('yes') yes >>> if "": print('yes') >>> if []: print('yes') >>> if [2,3,4]: print('yes') yes >>> ['',''] ['', ''] >>>