总结一个数字列表比与for循环更快的方法? [英] Faster way to sum a list of numbers than with a for-loop?
本文介绍了总结一个数字列表比与for循环更快的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案你可以使用sum()来求和一个数组的值。 b
a = [1,9,12]
印刷金额(a)
Is there a way to sum up a list of numbers faster than with a for-loop, perhaps in the Python library? Or is that something really only multi-threading / vector processing can do efficiently?
Edit: Just to clarify, it could be a list of any numbers, unsorted, just input from the user.
解决方案
You can use sum() to sum the values of an array.
a = [1,9,12]
print sum(a)
这篇关于总结一个数字列表比与for循环更快的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文