How to split three-digit numbers in Python

(*-*)浩
Release: 2019-07-04 14:05:24
Original
23107 people have browsed it

How to split three-digit numbers in Python

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))#将顺序倒过来
Copy after login

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))
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!