作者:羽林尉链接: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 + mprint('s = ', s, type(s)) ''' 方法三:Python内建的高阶函数 '''t = reduce(lambda x, y: x * 10 + y, M)print('t = ', t, type(t))
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务