def mysum(items):
head,*tail = items

return head+sum(tail) if tail else  head

每次加列表尾部的首部,递归终止条件是 tail列表为空

*符号的用法

python递归实现序列求和

相关文章: