How to sum a list of numbers stored as strings

后端 未结 2 1924
鱼传尺愫
鱼传尺愫 2021-01-17 05:50

Having a list of numbers stored as strings how do I find their sum?

This is what I\'m trying right now:

numbers = [\'1\', \'3\', \'7\']
result = sum(in         


        
2条回答
  •  心在旅途
    2021-01-17 06:32

    If you prefer a less functional style, you can use a generator expression

    result = sum(int(x) for x in numbers))
    

提交回复
热议问题