更新时间:2023-02-10 17:39:32
首先将整数转换为字符串,然后使用map
在其上应用int
:
Convert the integer to string first, and then use map
to apply int
on it:
>>> num = 132
>>> map(int, str(num)) #note, This will return a map object in python 3.
[1, 3, 2]
或使用列表理解:
>>> [int(x) for x in str(num)]
[1, 3, 2]