|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- def get_digits(n,result = []):
- if n == 0:
- return result
- else:
- return get_digits(n//10, result.insert(0, n%10))
- a = get_digits(12345,result = [])
- print(a)
复制代码
定义了result为列表,为什么报错说:
AttributeError: 'NoneType' object has no attribute 'insert'
还是说代码哪里有问题,新手求解答
本帖最后由 1q23w31 于 2020-8-25 15:40 编辑
- def get_digits(n,result = []):
- if n == 0:
- return result
- else:
- result.insert(0, n%10)
- return get_digits(n//10, result)
- a = get_digits(12345,result = [])
- print(a)
复制代码
insert方法没有返回值,所以报错
|
|