sum(list(map(int,list(str(i)))))==n
时间: 2024-05-20 08:16:33 浏览: 11
This is a Python expression that checks if the sum of the digits of a number i is equal to a given integer n.
Here's how it works:
1. `list(str(i))` converts the integer `i` into a string and then creates a list of its characters (digits).
2. `map(int, ...)` applies the `int` function to each character in the list, converting them back to integers.
3. `list(...)` creates a new list from the result of the `map` function.
4. `sum(...)` computes the sum of all the integers in the list.
5. The expression `sum(...) == n` checks if the sum is equal to the given integer `n`.
Overall, this expression can be used to check if a number `i` satisfies a certain condition, such as being a "Narcissistic number" (where the sum of the digits raised to the power of the number of digits is equal to the number itself).
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)