二分算法:
def two_mothod(num,li,start,end): mid=int((end+start)/2) if start<=end: if (num>li[mid]): return two_mothod(num, li, mid+1, end) if(num<li[mid]): return two_mothod(num,li,start,mid-1) if(num==li[mid]): return mid else: return False list=[1,2,3,4,5,6,7,8] end=len(list)-1 print(two_mothod(8,list,0,end))