#查詢元素是否在tuple內,有七種方法 #(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] #方法2:查詢元素a.index(txt) #[1,2,3].index(2) # => 1 #[1,2,3].index(4) # => ValueError a=['tom','mike','peter','yellow'] name = input('請輸入查詢姓名?') try: res = a.index(name) print(name + '找到了,在編號為' + str(res) +'的位置') except ValueError: print(name +'找不到')