将列表中的所有数字相加(不求和).的Python 3.3.2 [英] Adding all the numbers from a list together(not summing). Python 3.3.2

查看:415
本文介绍了将列表中的所有数字相加(不求和).的Python 3.3.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有此列表:

alist = [2, 0, 1]

我如何使名为"haha​​ha"的字符串例如等于201?不是5(总和). 我需要像"

How would I make a string named "hahaha" for example equal to 201 ? Not 5 (sum). Would I need to something like "

for number in alist .....

谢谢!

推荐答案

您可以使用 map() :

You can use ''.join() in conjunction with map():

>>> alist = [2, 0, 1]
>>> ''.join(map(str, alist))
'201'

这篇关于将列表中的所有数字相加(不求和).的Python 3.3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆