python 简单题 第五期
(应该是没有拖更)
各位好,欢迎继续赏光python简单题第五期
(呵呵,你要是没有鱼币,我都不会看上一眼的)
本次题目真的是简单题,原题我用不到5分钟做出来了.
(原题?那意思,你是不是要给改一下?)
是的....
不多说了,上题目了:
Given an integer n, add a comma (",") as the ten-thousand-separator and return it in string format.
Example 1:
Input: n = 987
Output: "987"
Example 2:
Input: n = 12345
Output: "1,2345"
Example 3:
Input: n = 123456789
Output: "1,2345,6789"
Example 4:
Input: n = 0
Output: "0"
Constraints:
0 <= n < 2^31
本次要求,你愿意用啥用啥方法,面向对象,面向过程,函数式...没有限制.
但是别废话
用python语言.
选出清晰的,简洁的,最快回答的.
给出25鱼币奖励!
截止时间:2020年9月30日
- def func(n):
- s = str(n)[::-1]
- return ','.join(''.join(s[i:i+4]) for i in range(0, len(s), 4))[::-1]
复制代码
|