Home > Article > Backend Development > How to Extract Digits from an Integer?
Extracting Digits from an Integer
How can you break down an integer into a list of its individual digits? For instance, transforming 12345 into [1, 2, 3, 4, 5].
Solution
To achieve this conversion, follow these steps:
Here's a Python implementation:
<code class="python">[int(i) for i in str(12345)]</code>
Example
Using the provided input of 12345, the code will execute as follows:
Result: [1, 2, 3, 4, 5]
The above is the detailed content of How to Extract Digits from an Integer?. For more information, please follow other related articles on the PHP Chinese website!