To find the sum of a list of numbers in python, you can use the built-in function called sum()
. Simply pass in your list of numbers as an argument to the function like so:
main.py72 chars4 lines
This will output the sum of the list (which in this case is 15).
If you're working with a very large list, you can also use the math.fsum()
function, which is more accurate for floating-point numbers:
main.py101 chars6 lines
This will output the sum of the list (which in this case is 17.4).
gistlibby LogSnag