s = input("請輸入一個字符串:") while True: subStr = input("請輸入另一個字符串") if subStr == "exit": break; i = 0 count = 0 while i < len(s): j = s.find(subStr,i) if j > -1: count +=1 i = j + len(subStr) else: break; print("''{}'在'{}'中出現了‘{}'次".format(subStr,s,count))