I found SyntaxError in my code, i don't know why

How can use this simble (+=) to sum numbers in a list

Hello @simaouchen! Could you please provide what language you are using? If you are using Python, you could do:

mylist = [1,4,7]
sumoflist = sum(mylist)

Please show your code. Else we can’t help you. Faires0feast provides an example of summing up a list.

Note that += upon a list is defined to add to the list, not add numbers.


This will entirely depend on the language.

In most languages, you reference the ith element of an array using square brackets ([]):


If you want to use +=, it’s implied you’ve got an accumulative variable to store the sum of the array values:

sum = 0

You would need to loop through each element of your array, most likely using a for loop in your language, and add them to the sum variable:

sum += array_variable[element_index]

An example of a for loop looks like this:

int sum = 0;
for (int i = 0; i < array_length; i++) {
	sum += array_value[i];