使用内置format函数
d = 12345678
print format(d, ',')
其他方法
正则split
import re
d = 12345678
rsd = str(d)[::-1]
','.join(x for x in re.split(r'(\d{3})', rsd) if x)[::-1] # 子组拆分
divmod
d = 12345678
l = []
while True:
first, second = divmod(d, 1000)
l.insert(0, str(second))
if first:
d = first
continue
break
print ','.join(l)