#in.py #Demo the in operator #strings s = "asdfqwerty yabba dabba doo" if 'bba' in s: #True print("yes") else: print("no") if 'scooby' in s: #False print("yes") else: print("no") if '' in s: #True. every string has the empty string in it between every chararacter print("yes", s.find(''), s.count('')) #index of where first found. how many #a string of length n has n+1 empty strings in it else: print("no") if '' in '': #True. EVERY string has the empty string in it print("yes") else: print("no") #print(s.split('')) #split a string at each empty string CAN'T # 'in' is boolean. .find(substring) returns index where found, -1 if not found #Lists lst = [10,30,40,"hello", 3.1415] if 30 in lst: #True print("yes") else: print("no") if "hello" in lst: #True print("yes") else: print("no") if "hel" in lst: #False print("yes") else: print("no") if "" in lst: #False. An empty string could be an item in the list though. print("yes") else: print("no") #list does not have a .find() method # .index(val) returns index of where val is or is Error x = 40 if x in lst: print("found. at index:",lst.index(x)) #avoid the error of index when not found x = 50 if x in lst: print("found. at index:",lst.index(x)) else: print("not found") #avoid the error of index when not found