py 5.18
Posted liujjpeipei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了py 5.18相关的知识,希望对你有一定的参考价值。
一、递归函数
# import sys # sys.setrecursionlimit(10000) # count = 0 # def func(n): # n += 1 # print(n) # func(n) # func(count) # def age(n): # if n == 1: # return 23 # else: # return age(n-1) + 2 # print(age(4)) # l = [2,3,5,10,15,16,18,22,26,30,32,35,41,42,43,55,56,66,67,69,72,76,82,83,88] # for i in range(len(l)): # if l[i] == 66: # print(i) # l = [2,3,5,6,8,10]
二、二分查找
# def func(li,aim,start = 0,end =None): # end = len(li) if end == None else end #如果最开始查找,end = len() # min_index = (end - start) //2 + start # if start < end: # if aim > li[min_index]: # return func(li,aim,start = min_index+1,end = end) # elif aim < li[min_index]: # return func(li,aim,start = start,end=min_index) # elif aim == li[min_index]: # return min_index # else: # print(start,end) # return ‘没有此值‘ # print(func(l,9))
以上是关于py 5.18的主要内容,如果未能解决你的问题,请参考以下文章