Million annual salary python road - day11 - recursion

Recursive (whenever a function is called recursively, it should have a return value, return value to function properly recursive 'go' back)

A decent recursive:

1. continue to call itself

2. There are definite end condition

Recursive focus on "a delivery of a return"

def age(n):
    if n == 4:
        return 18
    else:
        return age(n+1)-2
print(age(1))

li = [1, 3, 4, "alex", [3, 7, 8, "TaiBai"], 5, "RiTiAn",[4,5,6,[7,[11,12,34,5],10,8,9]]]
def func(lst):
    for i in lst:
        if type(i) == list:
            func(i)
        else:
            print(i)
func(li)

Guess you like

Origin www.cnblogs.com/zhangchaoyin/p/11221145.html