Let’s write a simple python program to find the sum of an array.
It’s very simple to calculate the sum of an array in Python, you just have to use a python function called sum().
Here is the example snippet:
#set an array of integers arr = [10, 20, 30, 40, 50] #to calculate we just have to use sum() print ("Sum of the array: ") print sum(arr)
The output of the above program:
Sum of the array: 150
So, just create an array arr = [10,20] of integers in python and pass the array variable to the sum(arr) function to calculate the sum of integers.
The post Python program to find the sum of array appeared first on TutorialsMade.