作者:羽林尉
链接:https://www.nowcoder.com/discuss/69725?type=1&order=0&pos=30&page=1
来源:牛客网
M = [i for i in range(1,10)]
''' 方法一:字符串拼接 '''
f = '' f = f.join(str(x) x for x in M)
print('f = ',f, type(f))
''' 方法二:循环 '''
for index, m in enumerate(M):
if index == 0 :
s = m
else:
s = s * 10 + m
print('s = ', s, type(s))
''' 方法三:Python内建的高阶函数 '''
t = reduce(lambda x, y: x * 10 + y, M)
print('t = ', t, type(t))