Use mathematical methods to split (recommended learning: Python video tutorial)
The three-digit numbers are units, tens, and hundreds. They can be separated by dividing by 10.
n=123 while (n>0): l.append(n%10) n=n/10 l=list(reversed(l))#将顺序倒过来
At this time, split 123 into [1,2,3] and display it in a list
Of course, if it is python, there is a simpler way to convert the number into String
l=list(str(n))
Only one line is needed to achieve the result we want
For more Python-related technical articles, please visit the Python Tutorial column to learn !
The above is the detailed content of How to split three-digit numbers in Python. For more information, please follow other related articles on the PHP Chinese website!