如何将整数拆分为数字数组? [英] How to split an integer into an array of digits?

查看:88
本文介绍了如何将整数拆分为数字数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的整数输入假设为12345,我想将其拆分为1, 2, 3, 4, 5.
我将如何做到这一点?

My integer input is suppose 12345, I want to split and put it into an array as 1, 2, 3, 4, 5.
How will I be able to do it?

推荐答案

>>> [int(i) for i in str(12345)]

[1, 2, 3, 4, 5]

这篇关于如何将整数拆分为数字数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆