Mic*_*ael -6 python python-2.7
这是我的代码:
def numbers_in_lists(string):
num = int(string)
l = list(num)
return l
string = '543987'
Run Code Online (Sandbox Code Playgroud)
当我运行它:
print numbers_in_lists(string)
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
l = list(num)
TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
谢谢.
num是一个整数,并list()期望一个可迭代,因此错误.你想获得一个表示数字的整数列表num吗?如果是这样,您可以尝试使用map():
l = map(int, string)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14979 次 |
| 最近记录: |