#查詢元素是否在串列list內,有七種方法 #(1).if txt in a #(2).res = a.index(s) #(3).matches = [x for x in lst if fulfills_some_condition(x)] #(4).matches = (x for x in lst if x > 6) #(5).next(x for x in lst if ...) #(6).for index, sublist in enumerate(lists): #if sublist[0] == key: #(7).[i for i,x in enumerate([1,2,3,2]) if x==2] #方法1:if txt in a a=['tom','mike','peter','yellow'] def find_list(txt,a): if txt in a: return txt + '存在list內' else: return txt + '不存在list內' txt = input('請輸入查詢姓名?') res = find_list(txt,a) print(res)