当前位置:网站首页>How to turn a multi digit number into a digital list

How to turn a multi digit number into a digital list

2022-07-06 20:38:00 huaMinPython

n=19

Method 1:

1. First convert numbers into strings .str(n)

2. Then convert the string into a string list .list(str)

3. Finally, convert each element into int.【int(i) for i in list】

  l=[int(i) for i in list(str(n))]   

Method 2:

use map(int,【】) function

  l=list(map(int,list(str(n))))  

n=19

# Method 1
#l=[int(i) for i in list(str(n))]

# Method 2
l=list(map(int,list(str(n))))

print(l)

原网站

版权声明
本文为[huaMinPython]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131156549154.html