案例一:(利用列表元素增删)
n = input('>>>')
src = list(n)
lst = []
def fn(num):
if len(num) == 0:
return lst
lst.append(num.pop())
return fn(num)
fn(src)
运行结果:
>>>1547
['7', '4', '5', '1']
案例二:(利用列表索引)
def out():
num = input('>>>')
def fn(n,lst=[]):
if n == -1:
return lst
lst.append(num[n-1])
return fn(n-1,lst)
return fn(len(num))
out()
运行结果:
>>>65464
['4', '6', '4', '5', '6', '4']
案例三:(利用数字特性)
def rev(n,lst=None):
if lst == None:
lst = []
a,b=divmod(n,10)
lst.append(b)
if a < 10:
lst.append(a)
return lst
else:
return rev(a,lst)
</