Python附加列表分配给None

时间:2018-10-17 07:47:08

标签: python list append

def add_this_many(x, el, lst):
     """ takes in a value x, a value el, 
    and a list and adds as many el’s to 
    the end of the list as there are x’s"""

    if x == 0:
        return lst
    else:
        tmp = lst.append(el)
        return add_this_many(x-1,el,tmp)

lst = [1,2,3,4,5]
add_this_many(1,5,lst)

您能告诉我为什么此递归调用不附加列表吗?它只是将tmp分配为None!列表是否有些特殊?

0 个答案:

没有答案