当前位置:主页 > 软件编程 > Python代码 >

在Python中,不用while和for循环遍历列表的实例

时间:2021-08-15 09:34:41 | 栏目:Python代码 | 点击:

如下所示:

a = [1, 2, 3, 8, 9]
def printlist(l, index):
  if index == len(l):
    return
  else:
    print(l[index])
    printlist(l, index + 1)
 
printlist(a, 0)

*****for和while循环底层用的是递归实现的

您可能感兴趣的文章:

相关文章