TypeError:'int'对象不可迭代; Python 2.7

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)

我怎样才能解决这个问题?

谢谢.

ars*_*jii 5

num是一个整数,并list()期望一个可迭代,因此错误.你想获得一个表示数字的整数列表num吗?如果是这样,您可以尝试使用map():

l = map(int, string)
Run Code Online (Sandbox Code Playgroud)