how to sum only the even values in python

Solutions on MaxInterview for how to sum only the even values in python by the best coders in the world

showing results for - "how to sum only the even values in python"
Benoit
06 May 2016
1>>> myList = [1, 3, 5, 6, 8, 10, 34, 2, 0, 3]
2>>> result = 0
3>>> for item in myList:
4...     if not item%2:
5...             result += item
6...
7>>> result
860
Johanna
16 Feb 2019
1>>> myList = [1, 3, 5, 6, 8, 10, 34, 2, 0, 3]
2>>> result = 0  # Initialize your results variable.
3>>> for i in myList:  # Loop through each element of the list.
4...   if not i % 2:  # Test for even numbers.
5...     result += i
6... 
7>>> print(result)
860
9>>>